I think you are experiencing an unsuccessful clash of two different paradigms here. On the one hand, you have the AJAX style API that you want to use, and on the other hand, you have an ASP.Net back page.
Now, although the two are not mutually exclusive, they can present some problems. I agree with Dan that it is best to lean a bit towards the AJAX approach, and not vice versa.
A good feature of ASP.Net is the ability to turn one static method into your page into a pseudo-web service. You can then use ScriptManager to create client-side proxy classes to call this method for you, but you can use any client-side library you want .
A very simple example:
In your code for you Page
[WebMethod] public static Person GetPerson(Int32 id, String lastName) { return DataAccess.GetPerson(id, lastName); }
If you used the ASP.Net AJAX library to handle this for you, you will need to include page methods to create client proxies.
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager>
Then you can call it the client side script as follows:
function CallGetPerson() { var id = $get("txtPersonId").value; var lastName = $get("txtLastName").value;
Now again this is a contrived example, and what you send to the server can be very complicated, but you get a general idea of what can be done using the built-in infrastructure components.
Hope this helps.
source share