r12
r12

Reputation: 59

how to redirect page using java script

m using java srcipt messagebox..

private void MessageBox(string msg)
    {
        System.Web.UI.WebControls.Label lbl = new System.Web.UI.WebControls.Label();
        lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "');</script>";
        //lbl.Text = "<script>window.alert('" + msg + "');</script>";
        Page.Controls.Add(lbl);
    }

now i want to reload my page..but if i write response.redirect my messagebox is not display....i write this function in code behind and call it when i need to display messagebox...so, how can i reload my page???????

Upvotes: 0

Views: 838

Answers (1)

naivists
naivists

Reputation: 33551

Like this

lbl.Text = "<script>window.alert('" + msg + "');window.location.replace('yourotherpage.aspx')</script>";

But please don't forget to properly escape the quotes in your "msg" text. Otherwise you may get a broken script code.

Upvotes: 3

Related Questions