65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.04/5 (18 votes)

Nov 16, 2011

CPOL
viewsIcon

63784

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:
 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:
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:
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);