Button click/page submit from JavaScript
<p>I'd like to understand how the asp.net framework knows when a button has been clicked and therefore once it receives the request fires its click event on the server.</p>

<p>I need to understand how it works as I would like to trigger the button's server click event from javascript.</p>

<p>I am able  to perform a submit of the page from JavaScript:</p>

<pre><code> document.forms[0].submit();
</code></pre>

<p>But how could do the same so that asp.net thinks that a button click has happened, so on the server its click event fires once the request is received.</p>

<p>Thanks</p>

<p><strong>UPDATE 1</strong></p>

<p>Thanks everybody for the replies. Doing a few tests if I add one asp.net button and by looking at the source code, I cant seem to find a generated JavaScript "__doPostBack" function.</p>

<p>This is the test I've tried. </p>

<p>I have one normal HTML button (button1) and an asp.net button.(button2)  </p>

<p>From the HTML button's click event (button1), I've added a client call to the javascript __doPostback method passing in the asp.net button2 id. </p>

<p>So I am trying to fire the server side button2 click event by calling the html button (button1.)</p>

<p>  </p>

<pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;  
&lt;head runat="server"&gt;  
    &lt;title&gt;&lt;/title&gt;  
&lt;/head&gt;  
&lt;body&gt;  
    &lt;form id="form1" runat="server"&gt;  
    &lt;div&gt;  
        &lt;input id="Button1" type="button" 
         value="Raise Button2 server side click event"
         onclick="javascript:__doPostBack('Button2', '')" /&gt; 

        &lt;asp:Button ID="Button2" runat="server" 
        Text="asp.net_Button2" 
        OnClick="button2Click" /&gt;  
    &lt;/div&gt;  
    &lt;/form&gt;  
&lt;/body&gt;  
&lt;/html&gt; 
</code></pre>

<p>And the generated HTML:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;&lt;title&gt;
&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form name="form1" method="post" action="Default6.aspx" id="form1"&gt;
&lt;div&gt;
&lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUKMjA0OTM4MTAwNGRke29WUkB+FLhQArxd1ehT98cWw1Y=" /&gt;
&lt;/div&gt;

&lt;div&gt;

    &lt;input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" 
value="/wEWAgKLs+3sDgK7q7GGCBs2MBvLk9CJNnA02t08R1LKdiJU" /&gt;
&lt;/div&gt;
    &lt;div&gt;
        &lt;input id="Button1" type="button" value="Raise Button2 server side click event" 
onclick="javascript:__doPostBack('Button2', '')" /&gt;
        &lt;input type="submit" name="Button2" value="asp.net_Button2" id="Button2" /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;  
</code></pre>

<p><strong>UPDATE 2</strong>  </p>

<p>If I set the buttons "UseSubmitBehavior" attribute to false, then it does generated the __doPostBack method and by calling it from the client it does raise the event on the server.</p>

<p>So what would be the difference between submit and a postback? (I'll start a new thread for this).<br>
Thanks for the help!</p>
