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//*
0
codispdp
7/11/2004 1:20:38 PM
asp.net.client-side 24353 articles. 0 followers. Follow

1 Replies
540 Views

Similar Articles

[PageSpeed] 26

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
0
fozylet
7/12/2004 8:14:52 AM
Reply:

Similar Artilces:

Calling server side sub from client side button click
Hi, I have some javascript in my asp.net page, and a function within that, which is run when the client side form is submitted. What I need is for that function to run, which updates a server side variable, then following that a server side sub should run, using that (newly updated) variable. I have currently set it up with the  onsubmit= tag of the client side form running the first (JavaScript) function, and then the submit button at the bottom of the client side form calling the server side sub with its onClick property. The (probably quite daft!) thinking behind that was that the on...

Is it possible to call client side function from server side code without initial client request?
Atlas is great. I'm using timer to periodically check database changes on server to populate client side controls with new data. Is it possible to do it without a lot of client requests to server which takes a huge useless network traffic? Server should call client side function on all connected clients when, for example, 'database updated' event occurs on server. Thanks. Hi~ Just for your interest, I think you could have a look at Comet, many web IM like Gmail's embeded Gtalk and meebo.com are built on this architecture你好! Just FYI o_O...

Firing both Client side event and server side event for server side button
I am having some difficulties getting this to work.. I have button_click (Asp.net) and ClientClick (Javascript).  Javascript is firing fine.  Server script is not. may be you have return return false in the in the javascript which is why its not firing server side event.You should add javascript evelt like thisbutton1.onclientclick = "functionname" Function should nopt return false. Vikram www.vikramlakhotia.comPlease mark the answer if it helped you...

Calling a client side function from the server side
Is it possible to call a client side function from the server side. I dont want to invoke that function through button click. I just want to call that to do some operations.  Regards, Aish Use the below code ASP.NET 2.0 Page.ClientScript.RegisterStartUpScript(this.GetType(),"callfunction","<script language=javascript>Test();</script>"); ASP.NET 1.X Page.RegisterStartUpScript("callfunction","<script language=javascript>Test();</script>"); Where Test() is the javascript function. HCHaissam Abdul MalakMCAD.NET| Blog | No, it is not possible.  The cl...

How to call server side function on client side
Hi,   How to call server side function on client side? here i want to call change() function on textbox onchange event.   <script language="javascript">    function serverfunction()    {    }    </script><input id="Text1" onchange="javascript:serverfunction();"  type="text" /> code behind:  public void change()    {        Response.Write("hello");    } <script type=&quo...

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

How to Call server side and client side function on same LinkButton
hello,         i have one linkbutton when i click on linkbutton i insert record in DB using onclick=Linkbutton_click. if successfully insert then returnvalue is 1. after return 1 i want to call javascript function. how i can do this? Reply ASAP. Is It Possible? e.g. <asp:LinkButton ID="Operation_Link" runat="server" OnClick="Operation_Link_Click"></asp:LinkButton>protected void Operation_Link_Click(object sender, EventArgs e) {if (Operation_Link.Text == "SUBMIT") {ReturnValue = company.InsertCompany...

Call client side function from server side code
My problem is that in some point of the VB.Net code I need to call a function defined in vbScript, for example: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click   'There's some code here....   ' ...   If (SomeCondition) Then   'HERE'S WHERE I NEED TO CALL THE JAVASCRIPT FUNCTION... SO HOW CAN I DO THAT?   Else     '...   End If   ' ... End Sub The asp.net code runs to generate the html and when it is done the html is rendered in your browser. So you can't access cli...

Client side script calling Server side functions
Hi, I'm currently developing an ajax.net enabled aspx page that contains a usercontrol (which is based on the listbox but extends it to include icons to represent invalid data). http://www.djcharlie.co.uk/WeeeCareResolutionCentre.jpg I want the onClick event of the selected TR to call an asp.net server function which then populates the controls to the right hand side in the page. Obviously because the row is just rendered HTML overriden from the base class I can only assign a javascript function to the onClick event. So I need a way of calling a server side function that will populate th...

How to call server side function from client side JavaScript?
I want to call a server-side function, like a button's click event or just another private or public function , from a client-side JavaScript function. How do I do that? thanX AnzIf this post was useful to you, please mark it as answer.ClientSideAsp.Net | Blog Maybe alittle more that you need, but....... 1) Put a button on the page. Lets say its id is Button1. Make sure that its has causesValidation=false 2) Write the code for the button. 3) Write the following in the PAge_Load event Button1.Attributes.Add("onClick", "myJSFunction(); return false") 4) Copy this javascript...

Conditional Client Side and Server Side call same button
I have a submit button on a form that I want to first do the validation and if valid call a client side javascript function and then run through its click event handler currently I have this set up by adding this line in the Page_Loadmybutton.Attributes.Add("onclick", "javascript:ShowRunningDialog(this);");But if the page is not valid I don't want to call this client side function. As it is now the 'ShowRunningDialog' is obviously going to be called no matter what     if (Page.IsValid) mybutton.Attributes.Add("onclick", &qu...

Call server side function from client side javascript
I have a javascript where I either need to call an onclick even of a server link button or I need to be able to call a server side function.   The only thing is I cant use AJAX.  Is there any way I can do this or am I spinning my wheels. Thanks!-------------Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. I have a similar problem.  In my case, I would like to set a server-side session object from JavaScript.  Any suggestions?  Thanks.  Dan Sure, y...

calling server side function from client side script
i have a web form that includes a function named "koko()" in its server side class i want to write a script code in in its HTML script that will be run at the client side, and this client side script will call the function "koko()" from the server side. in brief : i want to call a server side function from a client side script... can you help me in this You can't call server-side code directly from client-side code. You can, however, trigger a postback that your server-side code watches for and triggers the server-side code appropriately. You can do some ...

Calling a server-side procedure from a client-side function
I have a server side function that executes a database stored procedure, and I need to be able to call it from a javascript function.  Is this possible (without using an iFrame)?  Post back the page or use Ajax. Eric Pascarello.com | Twitter epascarello | LinkedIn...

Web resources about - Call server-side page function from client-side button click - asp.net.client-side

Server Side Includes - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Google Cloud Platform simplifies server-side development for iOS w/ ‘Mobile Backend Starter’
... Mobile Backend Starter that first debuted for Android developers back in June. Google says the application helps to simplify the server-side ...

Free Cooling: the Server Side of the Story
Servers that support higher inlet temperatures could significantly reduce or even eliminate the cooling costs of the data center. We received ...


[Update: Check Now] Play Store For Android Gets Search Bar With Hamburger Flip In Server-Side Update
Google is pushing out an update to the Play Store's Android interface that replaces the action bar with a standard search bar. Inside are the ...

Server-side update makes Siri a stickler for succinctness
Siri is already well known for her wit and willingness to joke, but a recent server-side update has given Apple's digital assistant the ability ...

Japanese RIAA wants server-side music DRM for mobile phones
The Recording Industry Association of Japan—the Japanese version of the RIAA— …

New BaaS platform aims to eliminate writing server-side code
... offering for desktop and mobile developers that's now leaving its beta phase. By removing the need for writing code on the server-side, Backendless ...

Dart improves async and server-side performance
... Team Today's release of the Dart SDK version 1.3 includes a 2x performance improvement for asynchronous Dart code combined with server-side ...

Customize Google Using Server-Side Scripts
Google's services have a lot of powerful features, but they can't offer all the options requested by users. A popular way to customize Google ...

Resources last updated: 12/6/2015 8:45:41 PM