Where to put javascript code with "Server-side ASP.Net AJAX"?
If I want to use ASP.Net without the Microsoft AJAX Control Toolkit or JQuery on the client-side, there are 2 possibilities according to their website (http://www.asp.net/ajax/) :
- Server-Side ASP.Net AJAX Programming
- Client-Side ASP.NET AJAX Programming
Client-Side programming obviously is just the javascript-side of the coin which means you could use Javascript to send requests, parse the results etc.
What bothers me is the "server-side" counterpart. I understand that you can use an "UpdatePanel" to do partial page updates and such but if HTML content depends on data received by asynchronous calls or even when new content needs to be added to the DOM tree because of that, where would I insert the Javascript necessary to parse that data and add the required HTML in such a scenario?
From their website, they even make it sound like anything AJAX can be realized without using "custom" Javascrip开发者_StackOverflowt code on the client-side which seems odd to me.
Updatepanels are indeed intended to be used without any custom javascript code. You can create your page, add an event and modify the contents of the panel just the way you would, when using a real postback (when user clicks some button and submits the page); so just by using things like panel.Controls.Add(new Label() { Text="Hi" })
.
Basically create a new UpdatePanel, add a button and a label to it, and add a Button_Click event where you do a label.Text="blah"
to see this in action.
You use the PageRequestManager object on the client-side to listen for events generated during an asynchronous postback.
For more information check out this overview on MSDN:
http://msdn.microsoft.com/en-us/library/bb386571.aspx
精彩评论