I have an email compose page. When the user clicks on the "Send" button, if there is any error, the page is redirected to an error page. If the email is sent out successfully, it displays a javascript alert message. The way it's done now is using a label
control,
LblMessage.Text="<script language=javascript>alert('Your email has been sent successfully!');</script>";
All of this works fine. Now I want to redirect the user to the home page. So if the email is sent out successfully, I want to display the javascript alert message, then do a redirect to home page. But if I add the response.redirect after the alert code,
the alert never shows up. I tried changing the endReponse to true and false, it did not work. Any suggestions?
Based on my understanding, you have a page for sending mail. If sending the mail successfully, you want to redirect to the home page and then popup a message box to tell client that the mail has been sent successfully. The concern is how to popup the message
box after redirect. If I have misunderstood your concern, please let me know.
For this scenario, we can add a function in the home page to verify if we need to show the message. If the mail has been sent successfully, redirect to the home page with a parameter, for example: redirect to “home.aspx?Mail=true”. Then in the home
page onload event handler, check the parameter and estimate if we need popup the message.
For your reference, please refer to the following code. I hope it is helpful to you.
************ home.aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript"> function MailSent()
{
var queryString = document.location.search.replace('?','');
var parameters = queryString.split('&');
for (i=0; i<parameters.length; i++)
{
if (parameters[i].substring(0,5) == 'Mail=')
{
if(parameters[i].replace('Mail=','') == 'true')
{
alert('mail has been sent successfully');
return;
}
}
} }
</script>
</head>
<body onload="MailSent()">
<form id="form1" runat="server">
<div>
this is the home page
</div>
</form>
</body>
</html>
Sincerely,
Benson Yu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>alert('Your email has been sent successfully!');window.location='MainPage.aspx';</script>'");
string s = "alert('Your email has been sent successfully');var vers = navigator.appVersion;if(vers.indexOf('MSIE 7.0') != -1) { window.open('Index.aspx','_self');} else{ window.open('Index.aspx');window.opener=self;window.close();}";
ScriptManager.RegisterStartupScript(this,
this.GetType(),
"Information", s, true);
Change The Index.aspx to any aspx page according to your need
new2aspdotne...
Participant
1179 Points
354 Posts
Javascript alert, followed by Response.Redirect?
Sep 12, 2007 08:58 PM|LINK
Hi,
I have an email compose page. When the user clicks on the "Send" button, if there is any error, the page is redirected to an error page. If the email is sent out successfully, it displays a javascript alert message. The way it's done now is using a label control,
LblMessage.Text="<script language=javascript>alert('Your email has been sent successfully!');</script>";
All of this works fine. Now I want to redirect the user to the home page. So if the email is sent out successfully, I want to display the javascript alert message, then do a redirect to home page. But if I add the response.redirect after the alert code, the alert never shows up. I tried changing the endReponse to true and false, it did not work. Any suggestions?
Thanks.
A1ien51
All-Star
29935 Points
5821 Posts
Re: Javascript alert, followed by Response.Redirect?
Sep 12, 2007 09:43 PM|LINK
You need to do the redirect from the client
alert("foo");
window.location.href="foo.aspx";
Eric
Benson Yu - ...
All-Star
34797 Points
2497 Posts
Re: Javascript alert, followed by Response.Redirect?
Sep 18, 2007 09:02 AM|LINK
Hi new2aspdotnet,
Based on my understanding, you have a page for sending mail. If sending the mail successfully, you want to redirect to the home page and then popup a message box to tell client that the mail has been sent successfully. The concern is how to popup the message box after redirect. If I have misunderstood your concern, please let me know.
For this scenario, we can add a function in the home page to verify if we need to show the message. If the mail has been sent successfully, redirect to the home page with a parameter, for example: redirect to “home.aspx?Mail=true”. Then in the home page onload event handler, check the parameter and estimate if we need popup the message.
For your reference, please refer to the following code. I hope it is helpful to you.
************ home.aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function MailSent()
{
var queryString = document.location.search.replace('?','');
var parameters = queryString.split('&');
for (i=0; i<parameters.length; i++)
{
if (parameters[i].substring(0,5) == 'Mail=')
{
if(parameters[i].replace('Mail=','') == 'true')
{
alert('mail has been sent successfully');
return;
}
}
}
}
</script>
</head>
<body onload="MailSent()">
<form id="form1" runat="server">
<div>
this is the home page
</div>
</form>
</body>
</html>
Benson Yu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
kipo
All-Star
16475 Points
2811 Posts
Re: Javascript alert, followed by Response.Redirect?
Sep 18, 2007 09:14 AM|LINK
Try with this code:
windows_mss
Participant
1394 Points
303 Posts
Re: Javascript alert, followed by Response.Redirect?
Sep 18, 2007 09:17 AM|LINK
Try This If You Are Using Ajax Enabled Site
string s = "alert('Your email has been sent successfully');var vers = navigator.appVersion;if(vers.indexOf('MSIE 7.0') != -1) { window.open('Index.aspx','_self');} else{ window.open('Index.aspx');window.opener=self;window.close();}"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Information", s, true);Change The Index.aspx to any aspx page according to your need
NJoy Programming...
Blogging @ xploredotnet