How to get alert message before redirect a page
-
I'm using vs 2010. I need to display the message to user and redirect the page. I use the below line. ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "<script> alert('User details saved sucessfully');window.open('frmDisplayUsers.aspx');</script>", true); But I didn't get the alert message and the page was directly redirected. How to get alert message?
-
Answer:
Your code is opening window but you asking for a redirect, below is an example of a redirect: ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('User details saved sucessfully');window.location ='frmDisplayUsers.aspx';", true);
Pooja at Stack Overflow Visit the source
Other answers
You need to write: ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true); Please note that I have removed the script tags as the last parameter true means you must not use the script tag. This code worked for me. If you have any problem let me know. In addition you can use setTimeout to delay the window open that might not be a very bad choice.
Kamal Deep Singh
The best way, if possible, is to put the code into the OnClientClick. <asp:Button OnClientClick=" alert('blah?');" runat="server" /> The problem with putting it into a startupscript is that the startupscript is run on postback, not real time. The redirect will happen before the postback. (possibly) The other solution of course is to put the redirect into the startupscript code. The page will post back, the script will run and then it will redirect.
thantos
Related Q & A:
- How To Get All Components Based On A Schema And From A Particular Publication?Best solution by Tridion
- How do I display all categories on a page with a corresponding image?Best solution by Magento
- How to get all the content of a page?Best solution by Stack Overflow
- How to use angular-file-upload on a page properly?Best solution by angular-file-upload.appspot.com
- How to get my website on the first page of google search engine?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.