16.4 Forcing a Post Back from a Web Control Event

 <  Day Day Up  >  

You want to force a post back to occur when a Web control event fires.


Technique

Only a certain number of ASP.NET controls cause a post back to occur when the user manipulates them. One of these controls is the Button control because a user expects something to occur when he or she clicks the button. Some controls do not automatically perform a post back when they change. An example is the RadioButton control. By default, the RadioButton control does not cause a post back to occur when it's clicked. To cause a post back to occur in response to a change in a server control, set the AutoPostBack property of the control to true .

Comments

A trip from the client to the server is a lengthy process. Of course in this day and age, it's not as bad as it used to be, but then again, not everyone is using a broadband Internet connection yet. To reduce the trips an ASP.NET page might take in response to interaction from the user with a control, post backs do not occur for every control. The control's event handler is not called until some other control causes the form to be submitted. Internally, the ViewState of the page is written in HTML as a hidden control. This ViewState value is an encrypted string containing the current properties of each control. ASP.NET examines the ViewState when a form is submitted and compares each control's value to the current value within the posted data. If the ViewState value is different from the value in the post data, then an event has occurred and ASP.NET calls the corresponding event handler. If you set AutoPostBack to true , then any change within the control causes a post back to occur.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net