Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am getting very weird problem. I have a model pop extender and I am making user to fill fields in it. So if user misses some field/text box I wanted a message to be generated accordingly in the message box. It happened succesfully however when i Click Ok in the message box than whole of the page gets refreshed and hides the pop up. Than I have to go back again and repeat the process. M i missing something ? Please help. Here is my code for message Box:
C#
private void MessageBox(string msg)
  {
      // define a javascript alertbox containing
      // the string passed in as argument

      // create a new label
      Label lbl = new Label();

      // add the javascript to fire an alertbox to the label and
      // add the string argument passed to the subroutine as the
      // message payload for the alertbox
      lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";

      // add the label to the page to display the alertbox
      Page.Controls.Add(lbl);
  }
Posted
Comments
khangaldi 12-Jul-12 3:51am    
have you set autopostback="false" of your button?
pradiprenushe 12-Jul-12 3:55am    
I think you should use validation control for this purpose & if you dont want to use it then you can refer this link How to call alert message instead of adding label in page
http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript.aspx
http://www.codeproject.com/Articles/11098/Use-Call-RegisterStartUpScript-RegisterClientScrip

Hi,

I would say instead of adding this label you just set the modalpopup extender label value and show modelpopup extender using the show() method, make sure to set onClientClick=return false or set that button as okcontrolid for modalpopup extendar

Or else you can register startup script also, as you are using ajax in your page you need to user scriptmanager.registerstartupscript, pls refer ScriptManager.RegisterStartupScript
 
Share this answer
 
Comments
Taresh Uppal 12-Jul-12 11:10am    
i used this:
scriptmanager.registerstartupscript(params)...got it..
Thanx for the advice !!!
Shemeer NS 12-Jul-12 11:19am    
You're welcome
This popup message box should be shown in Page_Unload to make it work without any problems.

check out this link. it has a working messagebox class. use it or refer the code to solve your problem.

A Windows Form like MessageBox for ASP.NET Website[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900