Introduction: In previous articles i explained how to Show jQuery notification pop up message box and hide after 5 seconds in asp.net and Message box in asp.net website using JavaScript . and How to call java script function from code behind file in asp.net and how to redirect visitor from one website to another website using java script and Validate file extension while uploading image or file through File Upload control using JavaScript in asp.net | Use of CustomValidator control to validate fileextension before uploading image or file through FileUpload control in asp.net
Now in this article i will explain How to display/show message box and redirect to another page/website in asp.net using JavaScript.Some times it is required to show message box and then redirect to another page while creating asp.net application.Below is the simple example to do this using JavaScript.
Implementation: Lets create an example to see the concept in action:
Asp.Net VB Code to show message box and redirect to webpage/website
Protected Sub btnMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMsg.Click
Now in this article i will explain How to display/show message box and redirect to another page/website in asp.net using JavaScript.Some times it is required to show message box and then redirect to another page while creating asp.net application.Below is the simple example to do this using JavaScript.
Implementation: Lets create an example to see the concept in action:
Asp.Net C# Code to show message box and redirect to webpage/website
protected void btnMsg_Click(object sender, EventArgs e)
{
{
protected void btnMsg_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(),
"alert('Record saved
successfully.');window.location='default2.aspx';", true);
}
}
- If Using Update panel then use below script:
{
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('Record
saved successfully.');window.location='default2.aspx';", true);
}
Asp.Net VB Code to show message box and redirect to webpage/website
Protected Sub btnMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMsg.Click
Page.ClientScript.RegisterStartupScript(Me.[GetType](), Guid.NewGuid().ToString(),
"alert('Record saved
successfully.');window.location='default2.aspx';", True)
End Sub- If Using Update panel then use below script:
Protected Sub btnMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMsg.Click
ScriptManager.RegisterStartupScript(Me, Me.GetType(), Guid.NewGuid().ToString(), "alert('Record saved successfully.');window.location='default2.aspx';", True)
End Sub
End Sub
Note: This code will
redirect you to default2.aspx page after showing message box. You can also
redirect visitor to another website. To do so just replace the default2.aspx with http://www.webcodeexpert.com/.
Now over to you:
If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates
10 comments
Click here for commentsthanx a lot sir
ReplyYour welcome Saagar Soni..keep reading..:)
ReplyCan please explain how to create post a ad then show it into posted list and hide and show as require. i will thankful you. I regularly read you blog..
ReplyNice Blog Really Helpful ... Thank you
ReplyYour welcome Mehedi Hasan..keep reading and stay tuned for more useful updates like this,,:)
ReplyHi, I'm using VB.net & I tried putting ur statement ScriptManager.RegisterStartupScript(Me, Me.GetType(), "popup", "alert('Record saved successfully.');window.location='default2.aspx';", True)
Replyin button_click, but no response.
Any idea y? Thanks.
sir i want to use status update bar same as use in facebook,how can we build this box?
ReplyHi Lalit Sir,
ReplyI am Your New Member
Nice Code It Is......
Hi,
ReplyLalit Sir Nice Code It is........
Thanks Ravi for appreciating my articles..it is always nice to hear that my article helped anyone in learning asp.net..stay connected and keep reading..:)
ReplyIf you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..