Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

i have catch block like this
C#
catch (SqlException ex)
           {
             lblmsg.Text = ex.Message.ToString();

           }

but i want to display this message in message box ..., i tried this code it is not working..
Any help will be appreciated..



C#
catch (SqlException ex)
 { 
    string Msgscript = "<script>alert('" + ex.Message + "')/script>";    
 if (!Page.IsStartupScriptRegistered("myErrorScript"))    
 {         
 Page.ClientScript.RegisterStartupScript("myErrorScript", Msgscript);   
  } 
} 
Posted

 
Share this answer
 
Comments
Rahul Rajat Singh 11-Jul-12 6:34am    
Good answer. +5.
Prasad_Kulkarni 11-Jul-12 6:43am    
Thank you Rahul!
shashavali 12-Jul-12 6:34am    
Thats helpfull for me...

i guess ur missing this this link
http://www.codeproject.com/Articles/15990/An-Easy-Approach-to-Displaying-a-Message-Box-in-AS
Prasad_Kulkarni 12-Jul-12 7:04am    
Glad it helps!
hi shashavali

once try this

XML
Response.Write("<script>alert('"+ Server.HtmlEncode(ex.Message) + "')</script>");


Best of luck.
 
Share this answer
 
Comments
shashavali 12-Jul-12 6:31am    
Thank you.... for your valuable idea..
Your string is missing tag & comma
C#
string Msgscript = "<script>alert('" + ex.Message + "');</script>";

if (!Page.IsStartupScriptRegistered("myErrorScript"))
 {
 Page.ClientScript.RegisterStartupScript(this.GetType(),"myErrorScript", Msgscript);  

}
 
Share this answer
 
v3
Comments
shashavali 12-Jul-12 6:28am    
Thank u Very much....

But Replace (!Page.IsStartupScriptRegistered("myErrorScript"))
with (!(ClientScript.IsStartupScriptRegistered("myErrorScript")))
will be perfect one with NO warnings...!!!!
Response.Write("<script>alert('"+ Server.HtmlEncode(ex.Message) + "')</script>");
 
Share this answer
 

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