jquery submit - change input value before post
<p>I am trying to change the value of an input textbox before submitting a form using something like the following:</p>

<pre><code>$('#form1').submit(function () {
     $('#MyTextBox').val('test');
});
</code></pre>

<p>However, when debugging the btnSubmit_Click method on the server side, both Request.Form[MyTextBox.UniqueID] and MyTextBox.Text contain the "old" value of #MyTextBox.  It appears that the form is being submitted before the javascript completes running.  Any idea why this is happening?  The javascript definitely runs because if I add an alert, it pops up.  If instead of using the form submit function, I use the click button, it works and the new value gets posted to the server:</p>

<pre><code>$('#btnSubmit').click(function () {
     $('#MyTextBox').val('test');
});
</code></pre>

<p>The submit button is defined as:</p>

<pre><code>&lt;asp:Button ID="btnSubmit" runat="server" CausesValidation="True"
Text="Submit" OnClick="btnSubmit_Click" ValidationGroup="submitRequest" /&gt;
</code></pre>

<p>Also on a separate note, is it better practice to use Request.Form[MyTextBox.UniqueID] or MyTextBox.Text in the server side method or does it not matter?</p>
