Click here to Skip to main content
15,889,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all. I have a webpage with an email function. Everything works but once the email has been sent, I want an alert box to appear after the user clicks submit and the email has been successfully sent...How can i accomplish this? i tried using this code...

C#
string cleanMessage = messagge.Replace("'", "\\'");
string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";

Page page = HttpContext.Current.CurrentHandler as Page;

if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
        {
         page.ClientScript.RegisterClientScriptBlock(page.GetType(), "alert", script);
        }

but no alert box appaers. Any help would be much appreciated, thanking you in advance.
Posted
Updated 7-Feb-13 22:03pm
v2

This code will help you show a client sided messagebox.
C#
private void MessageBox(string msg)
{
   Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('" + msg.Replace("'", "\\'") + "')</script>"));
}


You can use after your email send process such as;
example usage
C#
SmtpClient _Mail = new SmtpClient();
Mail.Send(mailMessage);
MessageBox("Email has been sent successfully.");


Good luck,
OI
 
Share this answer
 
Write this

C#
StringBuilder result = new StringBuilder();
            result.Append("<script type="\"text/javascript\"">  {");
            result.Append("alert('" + cleanMessage + "');}            result.Append("script>");
            ClientScript.RegisterClientScriptBlock(this.GetType(), "result", result.ToString());
 
Share this answer
 
v2
Try this one
C#
Response.Write(@"<script language='javascript'>alert('Mail sent successfully.');</script>");


Or, if you are using Update panel then try this one..
C#
ScriptManager.RegisterStartupScript(this, GetType(), "startprocesskey", "alert('Mail sent successfully.')", true);
 
Share this answer
 
v2
Comments
Ruwaldo 8-Feb-13 4:31am    
Thanks your second suggestion works perfectly

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900