I have two ASCX pages, call them Page1
and Page2
.
In the HTML of Page1, I define a ModalPopupExtender
. Now in the code behind on Page2
, I'd like to do a ModalPopupExtender.Show
when a button is clicked.
When I try to do this, I get an error stating the ModalPopupExtender
doesn't exist in current context. Is there a way to reference the ModalPopupExtender
defined in Page1
from Page2
so I can control it?
Expose your modal popup as a public property on your main page.
public class BasePage: System.Web.Ui.Page
{
public ModalPopupExtender MyPopup
{
get
{
return this.myPopup;
}
}
}
In your ascx code behind cast this.Page
to your page type.
public class Page1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
((BasePage)this.Page).MyPopup.DoWhatEver();
}
}