Link to home
Start Free TrialLog in
Avatar of jabcoco
jabcocoFlag for Canada

asked on

ModalPopupExtender raising even when user hit the OK button

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?

Thanks!!
Avatar of ASPSQLServerCOM
ASPSQLServerCOM
Flag of United States of America image

There is good explanation on what AJAX is at
http://en.wikipedia.org/wiki/Ajax_%28programming%29
http://www.skeymedia.com/programming/classic-asp-and-ajax-tutorial/
The reference site W3Schools has a good section on AJAX at http://www.w3schools.com/ajax/default.asp
Hi

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:
       LoadNewObjectPredefined();

       //show the modal popup
        mpe.Show();          
    }


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

JINN

 public void LoadMPENewObject()
    {
        ModalPopupExtender mpe = new ModalPopupExtender();
        mpe.PopupControlID = pnAddNewObjectPopup.ID;
        mpe.TargetControlID = btAddNew.ID;
        mpe.PopupDragHandleControlID = pnNewObjectCaption.ID;
        mpe.BackgroundCssClass = "modalBackground";
        plhNewobjectMPE.Controls.Add(mpe);
        mpe.Show();
          
    }

Open in new window

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
        ucNewObject.ClearForm();

        //Load predata and show popup
        LoadMPENewObject();
    }

JINN
ASKER CERTIFIED SOLUTION
Avatar of jabcoco
jabcoco
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

JINN
Avatar of jabcoco

ASKER

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 : https://www.experts-exchange.com/questions/23849113/How-to-hide-controls-inside-UpdatePanel-with-the-UpdateProgress-or-the-UpdatePanelAnimationExtender.html

thanks :)