ModalPopupExtender raising even when user hit the OK button

Posted on 2008-10-23
Last Modified: 2011-09-20
Just starting with Ajax .NET and i can't find how to call a server codebehind even "C#", when the user hit the "OkControlID" button.

Any other solution than setting a "OnOkScript" javascript and submiting a form?
Is it possible to simply tell the popup to call a server side event when the user hit the "OK" button?

Question by:jabcoco
  • 3
  • 2

Expert Comment

ID: 22793466
There is good explanation on what AJAX is at
The reference site W3Schools has a good section on AJAX at
LVL 10

Expert Comment

ID: 22794278

What I do is, I create a hidden field and set the TargetControlID to that field, the Ok button has it own Click event (which call server side function) and programatically show the ModalPopup, because I need to set values for that PopUp window, so this comes very handy.

 public void LoadMPENewObject()
       //Load new object data depend on pre user input:

       //show the modal popup

YOu can do the same thing, and even create the modal popup dynamically (look at my code)
(just incase you need reference)


 public void LoadMPENewObject()


        ModalPopupExtender mpe = new ModalPopupExtender();

        mpe.PopupControlID = pnAddNewObjectPopup.ID;

        mpe.TargetControlID = btAddNew.ID;

        mpe.PopupDragHandleControlID = pnNewObjectCaption.ID;

        mpe.BackgroundCssClass = "modalBackground";





Open in new window

LVL 10

Expert Comment

ID: 22794288
And this is the nomarl Button_Click event which load the previous code:

 protected void btAddNew_Click(object sender, EventArgs e)
       //clear the new object popup values

        //Load predata and show popup

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

LVL 10

Accepted Solution

jabcoco earned 0 total points
ID: 22808516
jinn_hnnl, what i was looking for is "executing" code behind C# when user hits the "Ok" button inside the modal popup, not showing a modal popup from code behind

Here is the solution i"m looking for

Thanks for your effort! :)


<asp:Panel runat="server" ID="panContent" CssClass="ajax_ModalPopup" Style="display: none">

  <asp:UpdatePanel ID="updtPanelModalPopup" runat="server">


      Login:<asp:TextBox ID="txtUser" runat="server"></asp:TextBox><br />

      Pass:<asp:TextBox ID="txtPass" runat="server"></asp:TextBox><br />

      <asp:Button ID="btnOk" runat="server" Text="LogOn" />




<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupCtrl"






void btnOk_Click(object sender, EventArgs e){

   ...//add your server side code and use modalPopupCtrl.hide() to close popup. and updtPanelModalPopup.Update();}

Open in new window

LVL 10

Expert Comment

ID: 22809014
Hi, sorry for late response.

Have you solved your problem? If you want to execute on any Button click as that button click is inside the ModalPopup, then just do it normally, set the OnClick event equals btnOk_Click, just like any another server button.

Incase you dont see anychanges was made, and actually the button was fired, page was posted back to server, but because you have that ok button inside the UpdatePanel, that's why only partly of the page/the updatePanel was updated. In that case, try to allocate the OkButton outside the updatePanel

Hope this help

LVL 10

Author Comment

ID: 22809093
jinn_hnnl, thanks! But has you can see i've solve my problem with the current question.

But i still have a other problem, maybe you can help on this ajax subject.
Please refer to :

thanks :)

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now