Skip navigation.

exploreopera

| Help

Sign up | Help

Hello World

Practical programming... and stuff...

AJAX in ASP.NET

, ,

Today I did some research and looked up how you do AJAX in ASP.NET 2.0.

Microsoft has released an AJAX extension for ASP.NET 2.0 which makes doing AJAX enabled pages very very easy. Let's compare the way you'd do AJAX in PHP to the way you use in ASP.NET.

In PHP you would probably create a page which answers to AJAX requests with the content they need. So basically you would have the main page which then has some JavaScript code that calls the other page which then responds with some other stuff which is put on the page with JavaScript again. Okay so that's pretty simple too.

But compare it to the method you can use in ASP.NET:

If you haven't ever seen ASP.NET code, just think of it as HTML with some extra tags that are ran server-side.

You have just a single page where you define an area of the page as an AJAX UpdatePanel. This lets you update the contents of that area with AJAX. Now, inside the UpdatePanel, you define a ContentTemplate. There you just place whatever code you want to show up at that point of the page.

That doesn't seem so brilliant. But wait, you can put pretty much anything inside the ContentTemplate and that code is also the one that is automatically used as the response for the AJAX request! Drop in some data from the database and that will be automatically used as the default content for the page and automatically updated based on some parameters from the page.

So basically this is what you need to AJAXify a page in ASP.NET:
<asp:UpdatePanel>
 <ContentTemplate>
  Whatever you want to ajaxify is here.
 </ContentTemplate>
</asp:UpdatePanel>

OK, so that is missing some attributes on the tags... but it's really simple!


I want to have this in PHP! :D

A problem with the Zend MVC patternDesign patterns: The Factory

Comments

avatar
Anonymous writes:

the difference with ASP.Net's version of AJAX is that in actuality the whole page is processed on the server, then only aspects that are inside the updatepanel are transfered to the client browser. So although the page does not 'refresh' the server is still being hit for a full refresh. MS doesn't really make this clear in it's documentation

By anonymous user, # 13. August 2007, 12:35:59

avatar
Yeah that's kinda what I thought it might do... However, it's still very easy to create AJAX functionality compared to, say, PHP.

Doing this is possible in PHP too, even with Smarty or such, but it would require quite much coding to be able to create a good library that you could reuse in different situations.

By zomg, # 13. August 2007, 12:49:16

avatar
Why would you do anything in ASP? >.>

By djahandarie, # 20. August 2007, 10:17:37

avatar
Why would you write such a pointless comment?

By zomg, # 20. August 2007, 15:03:12

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

Please type this security code : e1dafd

Smilies