Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call window.alert("message"); from C#?

Tags:

c#

asp.net

I have my own exception based on some condition and want to raise an alert when control comes in this catch block

catch (ApplicationException ex)
{
    //want to call window.alert function here
}
like image 409
NayeemKhan Avatar asked Sep 27 '10 12:09

NayeemKhan


2 Answers

Do you mean, a message box?

MessageBox.Show("Error Message", "Error Title", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

More information here: http://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox(v=VS.100).aspx

like image 137
Ruel Avatar answered Oct 04 '22 07:10

Ruel


It's a bit hard to give a definitive answer without a bit more information, but one usual way is to register a startup script:

try
{
  ...
}
catch(ApplicationException ex){
  Page.ClientScript.RegisterStartupScript(this.GetType(),"ErrorAlert","alert('Some text here - maybe ex.Message');",true);
}
like image 40
Jamiec Avatar answered Oct 04 '22 08:10

Jamiec