Call server-side page function from client-side button click

I have an existing ASP application that I am migrating to ASP.net. In the ASP app I was using the Microsoft.XMLHTTP on a the client-side of a ASP page to retrieve data from another asp page using the Microsoft.XMLDOM object. The client page passes 3 tags columns, table and Criteria. The receiving page builds the SQL statement executes the query and returns the row with all the column data.  I am trying to convert it over to ASP.NET and I am getting errors on the xmlDOM.Load(Request.InputStream) on DLookup.aspx,  the code is listed below.

Someone suggested to use System.Net HTTP classes such as WebClient or WebRequest.
I have been searching Google and have not found any examples of client-side script. Can someone give my some help in finding a solution?
*//Asp.net Client-Side Code Code//*
Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
xmlHTTP.open "POST", "/XMLFunctions/DLookup.aspx", False

strColumns = "CLIENT_NAME, REGION_DESC, LOGO, PHONE, ACCT_MGR, AFFILIATION, COORDINATOR_NAME, EXT, DESCRIPTION, COORD_CAS_ID"
' Send the columns, table and where clause

xmlHTTP.send("<REQUEST><sColumn>" & strColumns & "</sColumn><sTable>SIMBBA.V_WEB_HEADER_PLUS_ARCHIVE</sTable><sCriteria>PROFILE_NUM = " & ReqProfile &"</sCriteria></REQUEST>")

Set xmlDOM = CreateObject("Microsoft.XMLDOM")
xmlDOM.loadXML(xmlHTTP.ResponseText)

If xmlDOM.parseError <> 0 Then
Call msgbox ("Error :" & xmlDOM.ParseError.reason)
Exit Function
End If

'Create the XML root that will contain all the tag elements
Set xmlRoot = xmlDOM.getElementsByTagName("*")

'Loop through the collection of returned tags from the XML Function
'If you are selecting more then one column you must increment the index and subtract from the length
'For i = 1 To (xmlRoot.length-1) for 2 columns, -2 for 3 columns, -3 for 4 columns etc...
For i = 1 To (xmlRoot.length-9)
'strResults = (xmlRoot.item(i+1).text for 2 columns), (+2 for 3 columns), (+ 3 for 4 columns) etc...
ReqClientName = xmlRoot.item(i).text
ReqRegion = xmlRoot.item(i+1).text
ReqLogo =xmlRoot.item(i+2).text
ReqAcctMgrPhone = xmlRoot.item(i+3).text
ReqAcctMgr = xmlRoot.item(i+4).text
ReqAffiliation = xmlRoot.item(i+5).text
ReqProfileCoordinatorName = xmlRoot.item(i+6).text
ReqCoordExt = xmlRoot.item(i+7).text
ReqProfileDesc =xmlRoot.item(i+8).text
ReqCoordCasID = xmlRoot.item(i+9).text
i = i+9
'(i = i +2 for 3 columns), (+ 3 for 4 columns), (+ 4 for 5 columns)
Next
Set xmlHTTP = Nothing
Set xmlDOM = Nothing
Set xmlRoot = Nothing
*// End Client-Side Code //*
*// Start Server-Side Code//*
<%@ Page Language="vb"Debug="true" EnableSessionState=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OracleClient"%>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Xml" %>
<script Language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim oOracleConn As OracleConnection = New OracleConnection
Dim xmlDOM As XmlDocument
Dim strXML As String
Dim sColumn As String
Dim sTable As String
Dim sCriteria As String
Dim strSQL As String
Dim dt As DataTable
Dim dtCol As DataColumn
Dim dtRow As DataRow
Dim oCommand As OracleCommand
Dim da As OracleDataAdapter
Try
strXML = "<RESPONSE>"
xmlDOM.Load(Request.InputStream)
sColumn = xmlDOM.DocumentElement.GetElementsByTagName("sColumn")(0).FirstChild.Value
sTable = xmlDOM.DocumentElement.GetElementsByTagName("sTable")(0).FirstChild.Value
sCriteria = xmlDOM.DocumentElement.GetElementsByTagName("sCriteria")(0).FirstChild.Value
'Specify our SQL statement
strSQL = "SELECT " & sColumn & " FROM " & sTable & " Where " & sCriteria
oOracleConn.ConnectionString = Session("ConnectionString")
oOracleConn.Open()
oCommand = New OracleCommand(strSQL, oOracleConn)
da = New OracleDataAdapter(strSQL, oOracleConn)
da.Fill(dt)
If dt.Rows.Count < 1 Then
strXML = strXML & "<RESULTS>NOTFOUND</RESULTS>"
Else
For Each dtCol In dt.Columns
sColumn = dtCol.ColumnName
strXML = strXML & "<" & sColumn & ">" & Replace(dtRow(dtCol).ToString(), "&", "chr(38)") & "</" & sColumn & ">"
Next
End If
Catch exp As Exception
strXML = strXML & "Error Occured: " & exp.ToString
Finally
da = Nothing
da.Dispose()
oCommand.Dispose()
oOracleConn.Close()
oOracleConn.Dispose()
End Try
strXML = strXML & "</RESPONSE>"
Response.Write(strXML)
Response.End()
End Sub
</script>
*// End Server-Side Code//*
-1
codispdp
7/11/2004 1:20:38 PM
📁 asp.net.client-side
📃 24353 articles.
⭐ 2 followers.

💬 1 Replies
👁️‍🗨️ 2272 Views


The type of stuff you are doing looks better to be done on server-side, i think. The pointers you got regarding that is right, use System.Net to get the other pages, process it and send back to the user.

You could either use post-back (using form or javascript) or use a asp:button (?) control with a server-side on_click handler. both results in the same thing. Leave the details to you...
System.Net usage is like this...

Dim Request As System.Net.HttpWebRequest
Dim Response As System.Net.HttpWebResponse
Dim StreamHandler As System.IO.StreamReader
' Send the request to the server
Try
Request = System.Net.WebRequest.Create(URL)
'Request.Expect = "text/html"
Response = CType(Request.GetResponse, System.Net.WebResponse)
If Request.HaveResponse Then
If Response.StatusCode = Net.HttpStatusCode.OK Then
StreamHandler = New System.IO.StreamReader(Response.GetResponseStream())
GetPage = StreamHandler.ReadToEnd
End If
End If
Catch e As System.Net.WebException
'Handle...
Exit Try
Finally
End Try

            
:: Fozylet
-1
fozylet
7/12/2004 8:14:52 AM
Reply: