user279521
user279521

Reputation: 4807

Issues with displaying messagebox in asp.net

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);

Upvotes: 0

Views: 700

Answers (3)

Peter
Peter

Reputation: 2267

try these popups instead type java directly in the visualstudio GUI

On a button go to the "OnClientClick" property (its not into events*) over there type:

 return confirm('are you sure?')

it will put a dialog with cancel ok buttons transparent over current page if cancel is pressed no postback will ocure. However if you want only ok button type:

 alert ('i told you so')

The events like onclick work server side they execute your code, while OnClientClick runs in the browser side. the come most close to a basic dialog

as this codes is so small it should work unless they have really strange browser clients

Upvotes: 0

Hinek
Hinek

Reputation: 9739

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?

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

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.

Upvotes: 1

Related Questions