4

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?

Ahmed Atia
  • 17,848
  • 25
  • 91
  • 133

2 Answers2

8

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.

user229044
  • 232,980
  • 40
  • 330
  • 338
0

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>
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197