Click here to Skip to main content
15,895,784 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my Application i am using try catch block on web based application i want to show exception message in web with java script bt it is not working my code is below
C#
catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "ClientScript", "<script>alert(' "+ ex.Message.ToString() +" ');location.href='AddTender.aspx';</script>");
        }
Posted
Comments
What is the problem ?
Do you get any exceptions ?
Prasad Khandekar 6-May-13 4:29am    
A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.

Please ensure that the key "ClientScript" is unique.

Another simple alternative is

C#
Response.Write("<script type="text/javascript">");
Response.Write("alert('"+ex.Message+"');");              
Response.Write("</script>");
 
Share this answer
 
v2
Try using
C#
ClientScript.RegisterStartupScript 
 
Share this answer
 
Try this:
C#
Page.ClientScript.RegisterStartupScript(this.GetType(), "Error1", string.Format("<script type='text/javascript'>alert('{0}'); location.href='AddTender.aspx';</script>", ex.ToString().Replace("'", "\\'")));




--Amit
 
Share this answer
 
Comments
Vishal Pand3y 6-May-13 6:32am    
thnks @amit
_Amy 6-May-13 23:08pm    
Welcome.. :)

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