How do I access a property of a parent page, in a user control?

Michael Sterling
Michael Sterling used Ask the Experts™
on
I have a user control that loads, with a grid, at the same time that the page that contains the user control loads. I need to, show or hide, a column in the grid on the user control based on a value in the query string of the containing (parent page). Secondly, how do i access this from the user control,...and how do i reference the column, in the OnRowDatabound method of the grid in the user control?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
The UserControl should have a Page property. This corresponds to the control's hosting page. If you need access to a specific, public member of the page, then you can cast the Page to the specific class type. For example:
// In UserControl

private void SomeMethod()
{
    ((HostingPage)this.Page).PublicMember = "some value";  // Here, "HostingPage" corresponds to the class name "HostingPage", which is most likely in the page HostingPage.aspx.
}

Open in new window

Michael SterlingWeb Applications Developer

Author

Commented:
@kaufmed: i'll award you the points as your solution may work, as another way to solve my problem. i wound up putting the same querystring property into the user control as i did for the hosting page and that worked just fine. don't know why that wasn't an obvious possibility to me in the beginning. it does go along with the basic premise of your response to some degree, at least in my mind so it's "close enough"...thanks.
Michael SterlingWeb Applications Developer

Author

Commented:
thanks
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Cool. Glad you sorted it out  = )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial