What is the difference between client browser’s submit mechanism and the ASP.NET postback mechanism?

Button.UseSubmitBehavior property is used to gets or sets a value indicating whether the Button control uses the client browser’s submit mechanism or the ASP.NET postback mechanism.

So, What is the difference between client browser’s submit mechanism and the ASP.NET postback mechanism?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you set use submit behavior to false, ASP.NET will generate script to handle submit by calling “__doPostBack” method like the following code. The method will add value to event target for telling server which element fire current event.

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['ctl00'];
if (!theForm) {
    theForm = document.ctl00;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

<input type="button" name="Button1" value="Submit" onclick="javascript:__doPostBack('Button1','')" id="Button1">

In the other hand, if you set use submit behavior to true, ASP.NET will generate button as input type submit instead of type button. When use click this button, the form will be normally submited.

<input type="submit" name="Button1" value="Submit" id="Button1">

Both ways are not difference at the server-side. But if you set use submit behavior to true, it will generate a bit cleaner XHTML.

Method 2

Based on the docs you referenced it seems that the default behavior submits a form using the standard submit button in a form, while setting it to false will instead do something like:

<input type=button onclick="submitForm()" />

The default form behavior is:

<form><input type=submit /></form>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x