Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an error message box in a web application asp.net c#

I have an ASP.NET web application, and I wanted to know how I could display an error message box when an exception is thrown.

For example,

        try
        {
            do something
        }
        catch 
        {
            messagebox.write("error"); 
            //[This isn't the correct syntax, just what I want to achieve]
        }

[The message box shows the error]

Thank you

like image 945
zohair Avatar asked Mar 16 '09 18:03

zohair


People also ask

How does ASP.NET handle application level errors?

You can handle default errors at the application level either by modifying your application's configuration or by adding an Application_Error handler in the Global. asax file of your application. You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file.

What is application error C#?

Application level error handling allow to detect or handle web application level error handling so that its helps to handle and solve the particular error. Application level error handling can be done in 2 ways: 1. Add an Application_Error event handler to the global asax file for your web application.


1 Answers

using MessageBox.Show() would cause a message box to show in the server and stop the thread from processing further request unless the box is closed.

What you can do is,

this.Page.ClientScript.RegisterStartupScript(this.GetType(),"ex","alert('" + ex.Message + "');", true);

this would show the exception in client side, provided the exception is not bubbled.

like image 198
Ramesh Avatar answered Oct 12 '22 07:10

Ramesh