Hi,
I am creating a web app with VB.NET 1.1 using AJAX. I was wondering if there is a better way to handle events than what I am doing, without downloading an ajax framework.
My method:
Each button on web form calls javascript that creates an xml fragment and posts it to a class that handles ajax requests for the page.
XML:
The code on the server pulls out the command field and runs it through a select case to determine which function to call.Code:<AjaxRequest> <Command>Foo</Command> <Params> <Param name="param1">Bar</Param> <Param name="param2">Again</Param> </Params> </AjaxRequest>
Instead of this select case, are there better methods? It just seems like there should be...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 'Here is where the action is... 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
Thanks,
Ranthalion


Reply With Quote
Bookmarks