Force Postback from code behind? Or reload JavaScript from an Asynchronous Postback?

Posted by sah302 on Stack Overflow See other posts from Stack Overflow or by sah302
Published on 2010-05-07T20:38:55Z Indexed on 2010/05/07 21:08 UTC
Read the original article Hit count: 787

Hi all,

I've got a Jquery UI dialog that pops up to confirm the creation of an item after filling out a form. I have the form in an update panel due to various needs of the form, and especially because I want validation being done on the form without reloading the page.

JavaScript appears to not reload on an asynchronoous postback. This means when the form is a success and I change the variable 'formSubmitPass' to true, it does not get passed to the Javascript via <%= formSubmitPass %>. If I add a trigger to the submit button to do a full postback, it works. However I don't want the submit button to do a full postback as I said so I can validate the form within the update panel.

How can I have this so my form validates asynchronously, but my javaScript will properly reload when the form is completed successfully and the item is saved to the database?

Javascript:

    var formSubmitPass = '<%= formSubmitPass %>';
var redirectUrl = '<%= redirectUrl %>';

function pageLoad() {

    $('#formPassBox').dialog({
        autoOpen: false,
        width: 400,
        resizable: false,
        modal: true,
        draggable: false,
        buttons: {
            "Ok": function() {
                window.location.href = redirectUrl;
            }
        },
        open: function(event, ui) {
            $(".ui-dialog-titlebar-close").hide();
            var t = window.setTimeout("goToUrl()", 5000);
        }
    });

    if(formSubmitPass == 'True')
    {
        $('#formPassBox').dialog({
            autoOpen: true
        });
    }

So how can I force a postback from the code behind, or reload the JavaScript on an Asynchronous Postback, or do this in a way that will work such that I can continue to do Async form validation?

Edit: I change formSubmitPass at the very end of the code behind:

If errorCount = 0 Then
            formSubmitPass = True
            upForm.Update()
        Else
            formSubmitPass = False
        End If

So on a full postback, the value does change.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about JavaScript