Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Ajax
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:
  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 11-Jul-12 22:09pm
Comments
khangaldi at 12-Jul-12 3:51am
   
have you set autopostback="false" of your button?
pradiprenushe at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Taresh Uppal at 12-Jul-12 11:10am
   
i used this:
scriptmanager.registerstartupscript(params)...got it..
Thanx for the advice !!!
Shemeer NS at 12-Jul-12 11:19am
   
You're welcome
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  

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

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 12 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100