Id like to reference a property in my .aspx from my .ascx.
Lets say my page class is:
public partial class MyAdminPage : System.Web.UI.Page
I was expecting I could do from my .ascx:
MyAdminPage myPageInstance = (MyAdminPage)this.Page;
or
MyAdminPage myPageInstance = this.Page as MyAdminPage;
Which I cant.
How could I reference my page class from the .ascx?
Update 1
Thanks for the replies.
I forgot to mention that the .aspx has a master page, and within the contentPlaceholder is where I have the .ascx control.
So from my .ascx if I do:
this.Parent –> I get a reference to “ContentPlaceHolder”
this.Parent.Parent –> I get a reference to “HtmlForm”
this.Parent.Parent –> reference to a ‘MasterPage’.
I will not reuse the .ascx in any other .aspx pages just the one.
sJohnny’s comment is spot on, you should not be trying to modify parent (page) properties from the child (control). One good way to handle this situation is for the child to raise an event when it needs the parent to act. That way the parent can simply subscribe to the event and call whatever properties it needs at that time. This way your user control is in no way tied to the implementation of this particular page.