By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

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

P: 40
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

Expand|Select|Wrap|Line Numbers
  1. 1.private void MessageBox(string message)
  2.     {
  3.  
  4.         string tmp = "";
  5.         tmp = "<script language='javascript'>";
  6.         tmp += "alert('" + message + "');";
  7.         tmp += "</script>";
  8.         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", tmp);
  9.     }
  10.  
  11. 2. private void MessageBox(string message)
  12.     {
  13.       if (!string.IsNullOrEmpty(message))
  14.        {
  15.             Response.Write("<script  type=\"text/javascript\" language=\"javascript\">");
  16.             Response.Write("alert('" + message + "');");
  17.        Response.Write("</script>");
  18.         }
  19.      }

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
Nov 1 '10 #1
Share this Question
Share on Google+
2 Replies


Frinavale
Expert Mod 5K+
P: 9,731
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
Nov 1 '10 #2

P: 39
Hi Buddy,

below code may help to fix your problem.

Expand|Select|Wrap|Line Numbers
  1. ScriptManager.RegisterClientScriptBlock(Me, Page.GetType, "Validation", "function name", True)
Nov 2 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.