How to show alert message on button click in update panel in (C#).

Aman Sharma

 When you are using Ajax update panel, then normal alert function will not work. Here is the code to show alert message on button click(submit, cancel etc.)


  public void ShowAjaxMessage(System.Web.UI.Page page, string strMsg)


        string alertScript = "alert('" + strMsg + "')";

        ScriptManager.RegisterStartupScript(page, this.GetType(), "1", alertScript, true);



How to call this function on button click:


private void SaveRecord()


 //Code to save data

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



In alert function we are using

ScriptManager.RegisterStartupScript(Page page, Type type, string key, string script, bool addScriptTags)


We have to add namespace to use ScriptManager

i.e. using System.Web.UI;


Post a Comment

Post a Comment (0)

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

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