Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a code to display a successful message and redirect. The successful message is not displaying but it is redirecting to the next page. What did I do have wrong?

C#
try
       {
           cmd.ExecuteScalar();
           ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted the Enrollment Profile');", true);
           con.Close();
           Response.Redirect("Gradrate.aspx");
       }
       catch
       {

       }


I did try it different ways. it will show the message but not redirect or redirect but no message. Please Help!
Posted

1 solution

Hi
Try like this..



C#
protected void btn_Click(object sender, EventArgs e)
{
    string script = " <script type=\"text/javascript\"> alert('your message'); window.location='Gradrate.aspx';   </script> ";
    // if u r using ajax, use the following line
    //this.Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", script);

    ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", script, false);

}
 
Share this answer
 
Comments
Computer Wiz99 3-Dec-13 10:47am    
karthik mahalingam01, Thanks for the info but i don't know JS to much. Is there a way to put it in C#?
Karthik_Mahalingam 3-Dec-13 11:25am    
this is c# code only...

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