Leveraging Client-Side Enhancements in ASP.NET 2.0

ASP.NET 2.0 offers some interesting client-side enhancements that provide a higher-level abstraction to common web development chores so that developers don't have to dirty their hands with the intricacies of HTML & JavaScript. Scott Mitchell shares these 3 tips in a 4Guys.. article.

1) To maintain scroll position on postbacks, the MaintainScrollPositionOnPostback Page directive can be set to "true". To apply it to all pages in the website, it can be added to the pages element within the <system.web> element in web.config.

2) To programmatically set focus to a Web control on page load, the Focus() method (available for all Web controls in ASP.NET 2.0 including the TextBox Web control) can be used. Javascript for the ASP.Net 2.0 controls is typically generated by a request to webresource.axd. WebResource.axd is a new built-in HTTP handler in ASP.NET 2.0 that's used to retrieve script code into pages.

3) To perform a client-side action when a Button, LinkButton, or ImageButton is clicked, ASP.NET 2.0 introduces the OnClientClick Property. The required Javascript is automatically generated for the rendered page.

Comments