Client-Side Enhancements in ASP.NET 2.0

ASP.NET's model of Web controls, server-side event handlers, and view state work in unison to help blur the lines between the client and the server. In short, a developer designing an ASP.NET web page can think in terms of higher-level abstrations - TextBoxes, Buttons, Click events, and so on - and not have to worry about the low-level details of HTML, JavaScript, and how data is shuttled from the web server down to the client's web browser, and back again. However, it is important to be aware of the distinction between the client and the server.

Oftentimes, the overall user experience can be enhanced by intelligently adding client-side script. By associating script with client-side user actions, it is possible to provide a snappier user interface or to enhance the overall experience. For example, when clicking a Delete button on a web form, rather than blindly deleting the record or posting back to a confirmation page, client-side script can be used to display a confirm messagebox, asking the user if they're certain they want to proceed with the delete. Clicking OK would proceed with the postback, while clicking Cancel would short circuit it.

A client-side confirm messagebox.

Adding such client-side functionality in ASP.NET version 1.x almost always involved writing code. And for more advanced scenarios, the amount of code - both server-side and client-side - could easily explode. ASP.NET 2.0 has added a number of enhancements that make performing common client-side tasks as easy as setting a property. In this article we will look at how to programmatically set focus to a Web control, how to add client-side script when a Button is clicked, and how to maintain scroll position on postbacks.

Read more....

 

No Comments