validate textbox but postback resets hidden field?
<p>I have an asp.net button:</p>

<pre><code> &lt;asp:Button ID="MainContent_ibSave" runat="server" Text="Save" /&gt;
                &lt;/td&gt;
</code></pre>

<p>I need to keep the <code>runat=server</code> because I have to process some code behind when its clicked.
But in the jquery I have this:</p>

<pre><code> $("#MainContent_ibSave").click(function () {
            if ($('#MainContent_txtShipToName').val().length == 0) {
                $('#hErrorsExist').val("1");
                $('#error').show();
            }
            else {
                $('#hErrorsExist').val("0");
                $('#error').hide();
            }
</code></pre>

<p>Basically what I'm doing here is just checking if any text has been entered in #MainContent_txtShipToName.  I want to throw an error message if nothing is entered.  To do so I thought I'd add a hidden field:</p>

<pre><code>&lt;input id="hErrorsExist" type="hidden" /&gt;
</code></pre>

<p>To maintain the state of whether an error exists on the page or not.
This is so if an error exists on the form I can set the value to 1 otherwise I set it to 0.</p>

<p>After I click this button it sets the value to 1 shows the #error (which is just a div), but then the div disappears.  Its as if the postback has reset the value of hErrorsExist...</p>

<p>I even added a check in my jquery:</p>

<pre><code>  if ($('#hErrorsExist').val() == "0" || $('#hErrorsExist').val().length == 0) {
            alert("about to hide");
            $('#error').hide();
            alert($('#hErrorsExist').val());
        }
        else {
            $('#error').show();
            alert($('#hErrorsExist').val());
        }
</code></pre>

<p>This is the first thing in my document ready function.  I dont know how to handle this so that the div #error stays up even after the button post back.  If I do enter a value and it validates it should set hErrorsExist to 0 and hide the div #error and keep the div hidden after post back.</p>

<p><strong>Here's the full jquery:</strong></p>

<pre><code> $(document).ready(function () {
        /*hide message container on top*/
        //alert($('#hErrorsExist').val().length);
        if ($('#hErrorsExist').val() == "0" || $('#hErrorsExist').val().length == 0) {
            alert("about to hide");
            $('#error').hide();
            alert($('#hErrorsExist').val());
        }
        else {
            $('#error').show();
            alert($('#hErrorsExist').val());
        }

          $("#MainContent_ibSave").click(function () {
            if ($('#MainContent_txtShipToName').val().length == 0) {
                $('#hErrorsExist').val("1");
                alert("Setting to 1");
                alert($('#hErrorsExist').val());
                $('#error').show();
            }
            else {
                $('#hErrorsExist').val("0");
                alert("Setting to 0");
                alert($('#hErrorsExist').val());
                $('#error').hide();
            }
        });
          }); 
</code></pre>
