How to show alert message in (c#) on button click(not placed under update panel).

Aman Sharma

 You can use following function to show alert message in using c#. Ex. Show data saved or updated successfully.

**when you are not using ajax update panel.  

   public void showmessage(System.Web.UI.Page zpage, string zMessage)


            string alertScript = "<script language=JavaScript>";

            alertScript += "alert('" + zMessage + "');";

            alertScript += "</script" + ">";


            if (!zpage.IsClientScriptBlockRegistered("alert"))

                zpage.RegisterClientScriptBlock("alert", alertScript);


You can use above function to show messages as per your requirement.

How to call this function on button click:


private void SaveRecord()


 //Code to save data

  showmessage (this.Page, "Data saved successfully!")


 In alert function we are using

zpage.RegisterClientScriptBlock(string key, string script).


Here zpage is object of type class System.Web.UI.Page.


Post a Comment

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !