Let us understand how asp.net postback works
To better understand this function lets go step by step. Lets take any web server control except Button and ImageButton on a sample aspx page.
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Text="LinkButton" />
As you can see _doPostBack function takes two arguments viz. eventTarget and eventArgument. Moreover two hidden fields, “__EVENTTARGET” and “__EVENTARGUMENT,” are automatically declared which are used to store values of ‘eventTarget’ and ‘eventArgument’ respectively.
Ok if you have some confusion on these values are retrieved, lets do it ourselves to clear the things out. Take another control on web form, say another link button ‘LinkButton2’.
Insert break point on Page_Load event and hit F5. Click on LinkButton1, check the values that are retrieved in Page_Load event.
Button and ImageButton
However you can make Button to use asp.net postback mechanism by making use of Button.UseSubmitBehavior property (this property is not available for ImageButton control). UseSubmitBehavior property is of type bool and decides whether Button should use client browser’s submit behavior (Default. value = true) or asp.net postback mechanism (value = false).
Lets take two Button control on page:
<asp:Button ID="Button1" runat="server" Text="Uses browser submit behavior" UseSubmitBehavior="true" /> <asp:Button ID="Button2" runat="server" Text="Uses asp.net postback mechanism" UseSubmitBehavior="false" />
Note that you don’t have to specify UseSubmitBehavior=”true” explicitly as it is the default value/behavior. I have added it just for the sake of understanding. Now run this page and view its source in browser, you will these buttons rendered as follows:
Button2 for which we set UseSubmitBehavior property to false, will now use _doPostBack function to submit the form.
Hope this helps…Happy Coding!!!!