.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Looking deep inside PostBack and ViewState in ASP.NET 3.5

Posted By:Vishal Nayan       Posted Date: April 05, 2011    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

ASP.NET helps in rapid development of web forms in similar way our window counterpart writes code to develop window application for desktop. Development is rapid in window application because of many reason, i.e. there is no page life cycle etc.
 

Looking deep inside PostBack and ViewState in ASP.NET 3.5

Introduction:
ASP.NET helps in rapid development of web forms in similar way our window counterpart writes code to develop window application for desktop. Development is rapid in window application because of many reason, i.e. there is no page life cycle etc.

Major Difference between Window Application and ASP.NET

1) Web applications are executed on server, while window applications are executed at client side. In web application, users sees web forms in browser and provide inputs, which is posted back to server. ASP.NET handles this GAP between browser and server by a technique called PostBack, which send the page and all other user information to the server when certain action is performed.

2)ASP.NET used HTTP wire which is Stateless: for every round trip, and before the HTML output is rendered, all the user information and web page controls objects are destroyed. Although this is good to avoid heavy traffic application, but its challenging to maintain a seamless experience to user. So to maintain persistence state, ASP.NET uses a technique called ViewState.

3)Event Model: Window programmer have upper edge when it comes to programming rich event model, say programming for mouse click , key presses, or any other low level control interaction. But when it comes to ASP.NET, client actions happen at the client side and server processing takes place at server. This means there is certain amount of overhead involved in responding to event in ASP.NET

ASP.NET Control Automatic PostBack:

Description: The only option to send a page, both for HTML and ASP.NET is by clicking a submit button. Although when page is posted, ASP.NET fires other event. This model is extended in ASP.NET control with an Automatic Postback Feature. I.e. input control can fire different triggers and server side code can handle it immediately.

How it works: ASP.NET controls have property AutoPostBack. If set to True, ASP.NET uses client side abilities of javascript to bridge the gap between client-side and server side. It is set to False by default. Because to get optimum performance if we don't want to reach to a change event.

What ASP.NET does?

1) ASP.NET adds a javascript function to the rendered HTML page, "_doPostBack ()". When called, it trigger a postback , which is posting the page back to the server with all information.

2)ASP.NET adds two hidden input fields that the _doPostBack () function uses to pass information back to the server. One is ID of the control that raises the event and second is any other information.




3)doPostBack() sets these values with the appropriate information about the event and then submitting the form



4)ASP.NET generates _doPostBack() automatically.
5)Code inside this function grows, as more we add autopostback controls on the page.
6)Control whose AutoPostBack property is true is attached with _doPostBack() method by onClick or onChange property.
7)ASP.NET automatically changes a client-side JavaScript event into a server-side ASP.NET event, using the __doPostBack() function as an intermediary.

Real Example:

Say we have a List control whose AutoPostBack property is set to True. So it post back automatically when ever use changes the selection in the list, the client side onChange fires up. The browser then calls _doPostBack() which send page back to the server.

Download
vishalnayan_634375594900060000_ViewState.zip

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend