views:

3623

answers:

4

I'm fairly new to ASP.NET and trying to learn how things are done. I come from a C# background so the code-behind portion is easy, but thinking like a web developer is unfamiliar.

I have an aspx page that contains a grid of checkboxes. I have a button that is coded via a Button_Click event to collect a list of which rows are checked and create a session variable out of that list. The same button is referenced (via TargetControlID) by my ascx page's ModalPopupExtender which controls the panel on the ascx page.

When the button is clicked, the modal popup opens but the Button_Click event is never fired, so the modal doesn't get its session data.

Since the two pages are separate, I can't call the ModalPopupExtender from the aspx.cs code, I can't reach the list of checkboxes from the ascx.cs code, and I don't see a way to populate my session variable and then programmatically activate some other hidden button or control which will then open my modal popup.

Any thoughts?

A: 

Sorry, but I'm confused. You can't call an ascx directly, so...

Is your modal code that you are calling from within the same page, like a hidden panel, etc;

Or is it another aspx page that you are calling on a click event?

dustinupdyke
+3  A: 

All a usercontrol(.ascx) file is is a set of controls that you have grouped together to provide some reusable functionality. The controls defined in it are still added to the page's control collection (.aspx) durring the page lifecylce. The ModalPopupExtender uses javascript and dhtml to show and hide the controls in the usercontrol client-side. What you are seeing is that the click event is being handled client-side by the ModalPoupExtender and it is canceling the post-back to the server. This is the default behavior by design. You certainly can access the page's control collection from the code-behind of your usercontrol though because it is all part of the same control tree. Just use the FindControl(xxx) method of any control to search for the child of it you need.

DancesWithBamboo
+1  A: 

After some research following DancesWithBamboo's answer, I figured out how to make it work.
An example reference to my ascx page within my aspx page:

<uc1:ChildPage ID="MyModalPage" runat="server" />

The aspx code-behind to grab and open the ModalPopupExtender (named modalPopup) would look like this:

AjaxControlToolkit.ModalPopupExtender mpe = 
    (AjaxControlToolkit.ModalPopupExtender) 
          MyModalPage.FindControl("modalPopup");
mpe.Show();
Erick B
A: 

Thanks this really helped me!