Click here to Skip to main content
Click here to Skip to main content

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

, 20 Nov 2011
Rate this:
Please Sign up or sign in to vote.
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="/KB/tips/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="/KB/tips/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);

License

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

About the Author

mgrks

India India
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 Helpful in my current project. PinmemberVarun Sareen18-Nov-11 0:49 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 20 Nov 2011
Article Copyright 2011 by mgrks
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid