Common Query New Window
Common_QueryNewWindow_VBNet\TableDialog.aspx.vb
' Copyright 2010 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.
' 

Imports Microsoft.VisualBasic
Imports System
Public Partial Class TableDialog
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Try
      ' Get the random table id from the url's query string
      Dim id As String = Request.QueryString("id")

      ' Using the table id, retrieve the results data table from session
      Dim tableSessionKey As String = String.Format("dataTable{0}", id)
      Dim resultsDataTable As System.Data.DataTable = CType(Session(tableSessionKey), System.Data.DataTable)

      ' Make sure the data table was found
      If Not resultsDataTable Is Nothing Then
        ' Get the HTML form and div elements to add the results data table to
        Dim htmlForm As System.Web.UI.HtmlControls.HtmlForm = CType(Page.FindControl("form1"), System.Web.UI.HtmlControls.HtmlForm)
        Dim resultsDiv As System.Web.UI.Control = htmlForm.FindControl("resultsDiv")

        ' Create a new GridView control, bind the results data table to it, display it,
        ' and add it to the results div
        Dim resultsGridView As System.Web.UI.WebControls.GridView = New System.Web.UI.WebControls.GridView()
        resultsGridView.DataSource = resultsDataTable
        resultsGridView.DataBind()
        resultsGridView.Visible = True
        resultsGridView.BorderWidth = 10
        resultsDiv.Controls.Add(resultsGridView)
      End If
    Catch exception As System.Exception
      Dim jsAlertError As String = String.Format("<script>{0}</script>", GetJavaScriptErrorString(exception))
      Response.Write(jsAlertError)
    End Try
  End Sub

  ' Constructs JavaScript necessary to display an error message based on the passed-in exception.
  Private Function GetJavaScriptErrorString(ByVal exception As System.Exception) As String
    ' Get the website's configuration file
    Dim webConfig As System.Configuration.Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath)

    ' Get the "compilation" section of the config file
    Dim compilationSection As System.Web.Configuration.CompilationSection = TryCast(webConfig.GetSection("system.web/compilation"), System.Web.Configuration.CompilationSection)

    ' If the config file's compilation section specifies debug mode, include 
    ' stack trace information in the error message.  Otherwise, just return 
    ' the exception message.
    Dim errorMessage As String = Nothing
    If (Not compilationSection Is Nothing) AndAlso (compilationSection.Debug) Then
      Dim stackTrace As String = exception.StackTrace.Replace("\", "\\")
      errorMessage = exception.Message & "\n\n" & stackTrace.Trim()
    Else
      errorMessage = exception.Message
    End If

    ' Create a callback result to display an error message
    Dim jsAlertException As String = "alert('" & errorMessage & "')"
    Return jsAlertException
  End Function
End Class