Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / Javascript
Tip/Trick

How to show the message and redirect to other page in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.04/5 (18 votes)
20 Nov 2011CPOL 60.4K   17   9
We can simply do this by calling JavaScript in code behind.
The below code snippet is used to show the message and redirect to other page:

C#
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Access Denied. Please contact Administrator for access to this section.');location.href = 'login.aspx';", true);


The below code snippet is used to show the message and redirect to other page with parameters:

C#
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Data updated successfully. You will now redirected to search page.');location.href = 'somepage.aspx?name=" + name + "&address=" + address + "&state=" + state + "';", true);


The below code snippet is used to show the message and redirect to other page with parameters based on user confirm:

C#
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "var r = confirm('Data updated successfully. You will now redirected to search page.'); if (r == true) var str= 'somepage.aspx?name=" + name + "&address=" + address + "&state=" + state + "'; location.href = str ;", true);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 5 Good one Pin
demouser74321-Nov-11 2:28
demouser74321-Nov-11 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.