Saturday, March 10, 2012

Use several ModalPopupExtender to same target

Because you are using 2 different modalPopup extenders you can just use the targetControlID to determine where the call was coming from. So something to try would be to put a update panel around all the items in your panel of your modal popup. Then in the main code for the update panel put in some code that says something like.

if(modalPopup1.targetControlID =="coolIDname1"){//Do all the stuff u want when the first button is clicked}else{//do all the stuff u want when the second button is clicked}

And then in the .Click event for the button that you are using as the targetControlID make a call to the updatepanel in the modal popup to call the .update() event. This will make sure that when ever you click the button to show the modal popup, the panel will run its update code and check to see what button made the popup show.

I hope this make sense/works :)


This can be done with just 1 modalpopupextender, and 3 buttons (one will be hidden). Add a button to the page, and set the TargetControlID of the modalpopup to the ID of the new button. Then add the style="display:none;" to the button (make sure you DO NOT use the visible=false attribute). With the other 2 buttons you can then show the modal popup either in javascript or with a postback by calling the one of the following methods:

modalpopupextender1.Show() (for the server side)

or

$find('client_id_of_modalpopupentender1').show() (for javascript).

Eitherway you will now be able to set the contents of the panel to what you desire. Let me know if you need more help doing this.

-Alan


Since this is a commonly requested scenario we added an example on the Toolkit Sample website ModalPopup demo page. Give it a try and let us know if it was helpful.


I thank you all for your prompt and precise replies!!

I solved it using a third, invisible, button which acts as target for the single popupextender, and it works as I want it to.

Best regards,

No comments:

Post a Comment