concept postback in category .net

appears as: postback, postback, postbacks, postbacks, A postback
ASP.NET AJAX in Action

This is an excerpt from Manning's book ASP.NET AJAX in Action.

Listing 1.9. Setting AutoPostBack to true causes a postback and invokes the server-side code.

In ASP.NET, when a postback is about to happen, the first thing that is usually determined is which control invoked the process. Conveniently, the name of the control that invoked the postback is placed on the page in a hidden field called __EVENTTARGET. From managed code, one of the many ways you can examine its value is through the Params collection of the Request object:

string controlName = this.Request.Params.Get("__EVENTTARGET");

This works for most controls, but it isn’t supported for two common controls in the ASP.NET toolbox: Button and ImageButton. Instead of calling the __doPostBack JavaScript function that all other controls use, these button controls are rendered by the browser with simple input type='submit' tags. All these buttons do is cause the form to submit it to itself. When one of these buttons is clicked, you determine the control that invoked the postback by walking through the controls collection on the page and looking for the first and only button control. What about the other controls? Fortunately, this is the only input-type control added to the collection, so all you have to do is find the first (and only) button control in the collection.

Listing 7.8. Clicking the Abort button aborts the postback.

First, you put a Sleep call into the code-behind to slow down the update, essentially giving you a 5-second window (5,000 milliseconds) of opportunity to test the abort logic. Remember, calling Sleep is only for demonstration purposes and should never be implemented in production code. Next, you compare the ID of the element that initiated the postback with that of the Abort button on the page; if they match, you call the abortPostBack function in the PageRequestManager. The result is a premature end to the request.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest