How to excecute Javascript after failed form validation
<p>I am using ASP.NET 3.5, and the jquery.hint.js plugin. It works great, with one small problem. I have various ASP.NET validators on the page and when the page fails to validate, client-side, all of the textboxes that contained hint text are now blank. This is confusing for the end-user because their are no field labels. To see the hint text, they must click in and out of the field and it re-populates.</p>

<p>Not sure if it makes a difference, but these fields are wrapped in an ASP.NET AJAX UpdatePanel. The reason for the update panel is to do some asynchronous calls for dynamic field updates like auto-populating the state dropdown based on what country you choose. The form is submitted via postback.</p>

<p>I need a way to call the hint javascript against these fields after the validation fails on the client side. How can I do this?</p>

<p>Here is an example of the client side code that executes the hint plugin against the various fields on the page:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $(document).ready(function () {
        // Add handler function to UpdatePanel's events
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        PageLoad();
    });

    function PageLoad() {
        RetainState();
    }

    // This function handles the UpdatePanels' EndRequest event.
    function EndRequestHandler(sender, args) {
        if (args.get_error() == undefined) {
            RetainState();
        }
        else { // there was an error
            alert("There was an error" + args.get_error().message);
        }
    }

    function RetainState() {
        // Add hint to textboxes.
        $(":text").hint();
        $("textarea").hint();
    }
&lt;/script&gt;
</code></pre>

<p>One last thing: I thought I had already fixed this problem by adding the following code to the Page_Load method in the code behind, but if it was working before, it is not now:</p>

<pre><code>// This will call some javascript after a form validation fails
// and keep the hint text in the form fields.
if (!Page.ClientScript.IsOnSubmitStatementRegistered("KeepState"))
{
    string script = "RetainState()";
    Page.ClientScript.RegisterOnSubmitStatement(Page.GetType(), "KeepState", script);
}
</code></pre>

<p>Thanks,</p>

<p>Tod</p>
