Monday, June 10, 2013

Show message box in Asp.Net

Its easy and common to us but then also we are writing a same code again and again.

Here we have made a common function for show message box, which is more simple and better to look, call and apply.

 

Step 1: Put below code in Common class file.(if not created then create for all common functions. its a good habit)

 

//-----------Implementation-------------

   public static void MessageBox(Page p,string msg)

    {

        //System.Web.UI.Page p = new Page();

        ClientScriptManager cm = p.ClientScript;

        cm.RegisterStartupScript(p.GetType(), "alert", "<script>alert('"+msg+"');</script>");

    }

 

Step 2: how to call

 

Common.MessageBox(this.Page, "Test Message.");



HAPPY CODING!!!

ITWORLD
If you have any question then you put your question as comments.

Put your suggestions as comments