简体   繁体   中英

Need jQuery method to redirect after button click - ASP.NET, VB.NET, jQuery, Javascript

I have a page in one of my ASP.NET applications (VB) that relies on a 3rd party service being live, and I'm using jQuery to display an overlay if this service is found to be down. I've been using the same approach for other warnings in the app - the difference with this one is that it needs to redirect after the user clicks the button on the warning popup to remove the overlay. I've tried a number of different things, but in all cases the redirect is happening before the overlay warning is even visible. I understand why, I'm just not able to find a solution to fix it. Any assistance is greatly appreciated! I'm using the following code:

jQuery

function warn_redirect(msg, title, nextpage) {
    // show modal div
    //alert(obj.id);
    $("html").css("overflow", "hidden");
    $("body").append("<div id='popup_overlay'></div><div id='popup_window'></div>");
    $("#popup_overlay").addClass("popup_overlayBG");
    $("#popup_overlay").fadeIn("slow");

    // build warning box
    $("#popup_window").append("<h1>" + title + "</h1>");
    $("#popup_window").append("<p id='popup_message'><center>" + msg + "</center></p>");
    $("#popup_window").append("<div class='buttons'><center><button id='continue' class='positive' type='submit'>OK</button></center></div>");

    // attach action to button
    $("#continue").click(popup_remove_redirect(nextpage));

    // display warning window
    popup_position(400, 300);
    $("#popup_window").css({ display: "block" }); //for safari using css instead of show
    $("#continue").focus();
    $("#continue").blur();
}

function popup_remove_redirect(nextpage) {
$("#popup_window").fadeOut("fast", function () { $('#popup_window,#popup_overlay').trigger("unload").unbind().remove(); });
$("body", "html").css({ height: "auto", width: "auto" });
$("html").css("overflow", "");
window.location.href = nextpage;

}

(I added the window.location.href to my standard popup remove code, but I've tried other approaches, including triggering two actions from the button click.)

Here is the VB.NET calling code:

If Status = "DOWN" Then
            Dim clsUtility As New Utility
            clsUtility.Emailer("email@company.com", "email@company.com", "", "", "The Service Is Down!", "Please investigate")
            Dim ScriptString As String = "<script language='javascript'>"
            ScriptString += "warn_redirect('Some warning message.', 'Warning', 'AnotherPage.aspx');"
            ScriptString += "</script>"
            ClientScript.RegisterStartupScript(Me.GetType, "warnscript", ScriptString)
            'Response.Redirect("AnotherPage.aspx?ID=" & Session("SelKey") & "&UN=" & Header1.UserNumber) //this didn't work either
        End If

You're calling your function straight away here:

$("#continue").click(popup_remove_redirect(nextpage));

You want to do:

$("#continue").click(function() { popup_remove_redirect(nextpage); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM