How to show an alert message box for a button in update panel?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blacky
    New Member
    • Jan 2009
    • 40

    How to show an alert message box for a button in update panel?

    Hi,

    I have a webform all the controls are in a update panel,i have to write a script for showing error messages in a popup.

    These are the scripts i tried

    Code:
    1.private void MessageBox(string message)
        {
           
            string tmp = "";
            tmp = "<script language='javascript'>";
            tmp += "alert('" + message + "');";
            tmp += "</script>";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", tmp);
        }
    
    2. private void MessageBox(string message)
        {
          if (!string.IsNullOrEmpty(message))
           {
                Response.Write("<script  type=\"text/javascript\" language=\"javascript\">");
                Response.Write("alert('" + message + "');");
           Response.Write("</script>");
            }
         }

    these scripts work fine if the button is outside the update panel. I want scripts for displaying on a click of button which is inside update panel.Please reply asap.

    Thanks in advance,
    Blacky
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    When you are using UpdatePanels and JavaScript needs to be called, you must register the JavaScript with the ScriptManager. There are several methods available to let you register your JavaScript with the ScriptManager, so be sure to read the descriptions of each of them to choose the one best suited for your case.

    -Frinny

    Comment

    • krisssgopi
      New Member
      • Apr 2010
      • 39

      #3
      Hi Buddy,

      below code may help to fix your problem.

      Code:
      ScriptManager.RegisterClientScriptBlock(Me, Page.GetType, "Validation", "function name", True)

      Comment

      Working...