Wednesday, March 21, 2012

ModalPopup Abilitites

Hi All,

I’m having a few problems using the ModalPopup control and was wondering if anyone could help me out. Here goes:

1) If I want to use a user control as the popup control when using a modalpopup extender, is that possible? I have seen other people asking it but it doesn’t seem to be resolved whether one can specify the Ok Control and Cancel control as two controls within (children of) the usercontrol.

2) Is it possible to have more than one ok or cancel control for the popupmodal extender?

Thanks!

aloo

1. Should be possible - especially if you handle the ResolveControlID event to find the controls yourself.

2. Not by default, but you should be able to add additional OK buttons with onclick= handlers that simply click the "real" OK button. Similar for Cancel.


1. Works great, thanks.

2. How do you do that specifically in code? How do you programatically click a button from the event handler of another?


Hi a2mawani,

To programatically click a button you just get a reference to it and call itsclick function (i.e.$('MyOKButton').click(); is all it should take).

Thanks,
Ted

The above is javascript, yes? Sorry I'm new to the platform, how do you call that code from a server side event handler for the other buttons?

I.e. server side event handler for ButtonA and ButtonB have to call click for ButtonC


Hi a2mawani,

Yes, the code I showed was JavaScript. If you're doing it all on the server, then couldn'tButtonA's event handler just callButtonC's event handler (passing the same event args and passingButtonC as the source)?

Thanks,
Ted


Not sure how that works because I'm using this for the ModalPopup..... Basically I wanted to have 3 different ok buttons. So i created a 4th button that's hidden and I'll set the OkControilId of the ModalPopupExtender to the hiddenButton. I don't have a event handler for the hiddenButton because it's not really doing anything. Also, I thought that the modalPopupExtender intercepts the buttons click event to do its own stuff, will simply creating a handler for the hiddenButton and calling it do the trick?
Hi a2mawani,

I'm not really following what you're doing here... perhaps taking a look athttp://forums.asp.net/thread/1383860.aspx could help you out (especially David's suggestion). It should let you do whatever you want with your three buttons and then close the modal popup when they're done.

Thanks,
Ted

I'm sorry, you're right I havent been very clear as to what I'm trying to accomplish. Let me see if I can explain it better:

1) I have a single aspx page with 5 button controls labelled Button1..Button5

2) The user must be logged in to the site in order to use these buttons. So when a button is pushed, if the user is NOT logged in, I would like to display a modalpopup allowing the user to:

A) Login by filling in fields and clicking on a button named loginButton

B) Register by filling in fields and clicking a button named registerButton

C) Cancel the operation and dismiss the popup using a button named cancelButton

What I have So Far:

I) The popup I will be displaying is a user control containing all the controls for logging in/registering

II) I can bind one modalpopupExtender to a single Button (Button1) as the targetcontrol and to my usercontrol as the popupcontrol.

III) I can handle the ResolveControl event of the modalPopupExtender to find the cancelCancel button on my usercontrol because there is only one.

IV) I have the logic to log users in and register them in the apporpriate server side click handlers of the login and register button respectively.

V) The user control (which is what gets popped up) contains and update panel so that all the server calls happen async so the popup isnt dismissed once these buttons are pressed and the server side logic is performed.

What I can't do:

a) Bind the modalPopupControl so that the popup appears when any of Button1..Button5 is pressed. A requirement however, is that each button must perform serverside code to check the current login status BEFORE opening the modalPopup if necessary

b) Allow the loginButton or the registerButton dismiss the popup dialoge once the user has correctly logged in or registered. Another requirement of course is that both these buttons must perform server side code to check that the information entered was correct/valid.

Current Temporary Solution:

I currently only have a solution for problem b which is to allow the loginButton and registerButton to perform a Response.Redirect('currentPageUserIsOn.aspx") at the end of the server side onClick handlers. Obviously this isnt ideal becuase the screen is refreshed.

I know that was a lot but if any one has any ideas for overcoming these issues, please let me know! Thanks!

-aloo


Hi aloo,

I think I better understand what you're trying to do now. I think the answer to your first problem is to create a copy of theModalPopupProperties for each of your buttons. All the server code, controls, etc., should be the same with just theTargetControlID varying. To solve your second problem, I would again recommend taking a look athttp://forums.asp.net/thread/1383860.aspx. Since you don't have a specifc button to close the popup with server side, you can useRegisterStartupScriptto write some code that will close it when either a successful login or registration takes place.

Thanks,
Ted


I'm not sure if that will work because I only want the buttons (1 to 5) to show the modalPopup if the user is not logged in which will require some server side handling once the button is clicked to check the sign in status.
Is it possible to do the signed in check on Page_Load and then depending on the results, add the neccesserary ModulPopupProperties to the extender control?
Hi aloo,

Yes - you can create the extender properties you need dynamically in OnLoad. Check outFAQ Item #13 for more details.

Thanks,
Ted

No comments:

Post a Comment