views:

104

answers:

2

I have the following message box in c# on my asp.net page inside the btnSubmit_Click event. It tends to popup sometimes and not popup sometimes. Any reasons as to why it is not consistent?

ClientScript.RegisterStartupScript(
    GetType(),
    "alert",
    "alert('An email has been sent to Customer Service');",
    true);
+1  A: 

I guess that this will depend on the text you are putting inside the alert. In the example you provided the text is hardcoded but I suppose that in your real application this text is dynamic and might contain characters that break javascript such as '. Try using FireBug to see if there are some javascript errors when it doesn't work.

Darin Dimitrov
nope. No dynamic text.
user279521
@user, being that client side javascript is volatile, there could be errors with your script *or with other scripts present on the page* that could lead to your alert window not appearing. Check the error information.
Anthony Pegram
A: 

Have You checked, if the alert('An email has been sent to Customer Service'); line is in the HTML Source after you clicked the Button and the message did NOT appear?

If it isn't in the HTML, check:

  1. with the Debugger if your codeblock is hit
  2. are you maybe redirecting the response?
Hinek