Saturday, January 29, 2011

AJAX with ASP.NET

Imagine, you want to highlight a TextBox when the user moves the mouse over it. With the postback approach, you’d need to send the entire page back to the web server, regenerate it, and refresh it in the browser—by which point the mouse might be somewhere completely different. This approach is clearly impractical.

Ajax(Asynchronous JavaScript and XML)is programming shorthand for a set of techniques that create more responsive, dynamic pages. One of the hallmarks of Ajax is the ability to refresh part of the page while leaving the rest untouched.Ajax is nothing but JavaScript code that runs in the browser, requesting the new information from the web server when needed and updating the page accordingly.

The key benefit of Ajax is responsiveness, where as the challenges are code complexity and browser support.

TO use AJAX in ASP.net, we need to place a new web control ScriptManager on our page, and it’s the brains of ASP.NET AJAX .

If you’re using ASP.NET AJAX features throughout your website, you might choose to place the ScriptManager in a master page. However, this can occasionally cause problems, because different content pages may want to configure the properties of the ScriptManager differently. In this scenario, the solution is to use the ScriptManager in the master page and the ScriptManagerProxy in your content page. (You can find the ScriptManagerProxy on the same AJAX Extensions tab of the Toolbox.) Each content page can configure the ScriptManagerProxy control in the same way it would configure the ScriptManager.


All the elements and controls are kept between the tags.
When the UpdatePanel renders itself, it copies the content from the ContentTemplate into the page. This seems like a fairly unimportant low-level detail, but it does have one important side effect. If you want to use code to dynamically add controls to an UpdatePanel, you can’t use the UpdatePanel.Controls collection. Instead, you need to add new controls to the UpdatePanels.ContentTemplateContainer.Controls collection.

No comments: