Wednesday, January 25, 2012

How to display MessageBox in ASP.Net?


Like Windows Application MessageBox can be also displayed in ASP.Net web Application. It can be done after adding Window Application namespace to the ASP.Net application but this is not good practice because only for showing message box we should not add Window Application namespace.

We can try other alternative for this - Response.Write() method or Registering client side script with alert() method of javascript. Here is example-

To display MessageBox use this code-

 ClientScript.RegisterStartupScript(typeof(Page), "ScriptKey", ("<script>alert('Message')</script>"); 

OR

  Response.Write("<script>alert('Message')</script>");

Using this simple line we can display MessageBox in web Application.

Use this code in any Button_Click() event.

Thanks

No comments:

Post a Comment