-
March 17th, 2007, 04:18 AM
#1
Ajax Help
I am using asp.net 2003 and am using ajax in my application.currently
what am doing is that in my project i have another aspx page named ajaxEngine where all the server processes are done.After that i call a response.write() to send the xml file to my client side aspx page.
My doubt is that can't i use the code behind page of the same client side aspx page instead of another page like ajaxEngine
-
March 17th, 2007, 11:19 AM
#2
Re: Ajax Help
My doubt is that can't i use the code behind page of the same client side aspx page instead of another page like ajaxEngine
i dont understand your question. can you re-phrase it. do you mean you want your aspx pages to inherit the classes from the ajaxEngine.cs file? or do you want the ajaxEngine.aspx file to inherit from another page?
mcm
rate my posts!
mcm
-
March 17th, 2007, 02:07 PM
#3
-
March 28th, 2007, 08:39 AM
#4
Re: Ajax Help
Thanks for giving attention.
What i meant is that instead of using another aspx page for processing the client requests can i use the code behind (.aspx.cs) page of the client.
Now am using another page named ajaxEngine.aspx to process requests from my client.aspx page.from the ajaxEngine page am sending response in xml form to client page.
-
April 2nd, 2007, 08:22 AM
#5
Re: Ajax Help
Binil,
I just worked on something like this, too. I have .aspx pages and .aspx.vb code behinds. I am sending all my ajax requests via POST to AjaxHandler.vb. Our methods sound very similar.
First, I had to change all the urls that I send the request to. Instead of sending to myPage.aspx, I am sending to AjaxHandler.ashx. The request is forwarded to the AjaxHandler class by a modification in the web.config. Then, AjaxHandler does its work and sends back some xml to the client.
This is how I open the request in javascript:
this._xmlhttp.open('post', url, true);
And I send my xml document like this ( strUrl = AjaxHandler.ashx ):
a.call(strUrl, xmlDoc);
This is what I had to put into web.config (It goes in <system.web>):
Code:
<httpHandlers>
<!-- Simple Handler -->
<add verb="*" path="Ajax.ashx" type="GLRecon.Ajax, GLRecon" />
</httpHandlers>
Then, the AjaxHandler class looks a lot like this. It has to implement IHttpHandler...
Code:
Imports System.Web
Imports System.Xml
Public Class Ajax
Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
Get
Return True
End Get
End Property
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
Dim xmlDoc As XmlDocument
'If the XML document was submitted via post method, then load it in the DOM document
If (context.Request.InputStream.Length > 0 And context.Request.ContentType.ToString().IndexOf("/xml") > 0) Then
xmlDoc = New XmlDocument
xmlDoc.Load(context.Request.InputStream)
Select Case xmlDoc.GetElementsByTagName("Command").Item(0).InnerText
Case "Bar"
Call Bar()
Case "Func2"
Call Func2()
Case "HelloWorld"
Call HelloWorld()
...etc...
End Select
End If
End Sub
Public Sub Bar()
'Get params, do some work, and return something in the Response...
End Sub
End Class
Public Sub ReturnXML(ByVal context As HttpContext, ByVal rawXml As String)
If (rawXml = "") Then
Throw New ApplicationException("The value of rawXml was not defined.")
End If
context.Response.ContentType = "application/xml"
Dim xw As New XmlTextWriter(context.Response.OutputStream, New System.Text.UTF8Encoding)
xw.WriteRaw(rawXml)
xw.Close()
End Sub
End Class
Hope this helps you, my code is not fully functional as I could not post that to the forum, but this is pretty close, and should give you a good starting point, even though it's vb.net instead of c#.
-Ranthalion
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|