Click here to Skip to main content
13,048,584 members (79,708 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Posted 11-Jul-12 21:09pm
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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
Taresh Uppal 12-Jul-12 11:10am
i used this:
scriptmanager.registerstartupscript(params) it..
Thanx for the advice !!!
Shemeer NS 12-Jul-12 11:19am
You're welcome
Rate this: bad
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[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 12 Jul 2012
Copyright © CodeProject, 1999-2017
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