ScriptManager.RegisterStartupScript doesn't work on page redirection

245 Views Asked by At

I've got this block of code, which works fine:

if (ddlAuditComplete.SelectedItem.Value == "3")
{
    vState = 3;
    BindAccordions(Convert.ToInt32(Session["PlanID"]), Convert.ToInt32(Session["AuditID"]));
    if (vExit == 2)
    {
        ScriptManager.RegisterStartupScript(btnAuditComplete, typeof(Button), "Data Entry", "alert('At least one plan has not been closed properly')", true);
        return;
    }
}

Now, what I need to do is throw that popup and then redirect them to another page.

I tried this and it won't work:

if (ddlAuditComplete.SelectedItem.Value == "3")
{
    vState = 3;
    BindAccordions(Convert.ToInt32(Session["PlanID"]), Convert.ToInt32(Session["AuditID"]));
    if (vExit == 2)
    {
        ScriptManager.RegisterStartupScript(btnAuditComplete, typeof(Button), "Data Entry", "alert('At least one plan has not been closed properly')", true);
        String SUrl = "frmAuditSearch.aspx";
        Server.Transfer(SUrl, true);
        return;
    }
}

The above code will throw the user to the other page, but the popup never shows.

Can anyone tell me how to do both? Ideally, the popup will show up, once the user clicks OK it will re-direct them to the other page. But I'll also take it if the user gets re-directed first and then the popup shows up.

1

There are 1 best solutions below

0
AudioBubble On BEST ANSWER

Try this first shows message and then redirect to next page.

ScriptManager.RegisterStartupScript(btnAuditComplete, typeof(Button), "Data Entry", 
"alert('At least one plan has not been closed properly');window.location ='"+ SUrl +"';", true);

And remove:

Server.Transfer(SUrl, true);
return;