Ask the Expert

What does the PostBack method do?

What does the PostBack method really do? Why do we use it, when do we use it, and where do we use it?
Postback works by registering a javascript function named __doPostBack emitted by ASP.NET. This function is called by controls that cause postbacks, and causes the page form to be submitted to the server. This function is called passing the ID of the control causing the postback, and an optional argument to pass to the server-side event handler if it exists.

A server-side control can associate a client-side event to this function so that a postback is forced, for example, the "onclick" event on a control such as an image or a link.Your own custom controls can also participate in this process. You only have to use the Page. GetPostBackEventReference(Control control, string argument) method to render the call to the JavaScript client-side function. You also need to implement IPostBackEventHandler so that your control gets called whenever the postback function is called. You have to implement that interface method with the signature:
void RaisePostBackEvent(string eventArgument);
And you use postbacks automatically everytime you attach to an event on a server control.

This was first published in July 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: