By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,426 Members | 1,721 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

Access pages base class properties from User Control

P: n/a
Hi,

I have some properties that are common to all pages so I have created a base
class which every page inherits from. I now also want to use these
properties within User Controls on the page. Is there any way to get to
these properties through the parent property of the user control - I can't
seem to figure out how to get there. If I can't do this, do I have to do the
same thing as the page and create a base user control class with the same
code in - Seems silly to have to execute the same code twice on a page?

Thanks in advance for any help

Mike
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
UserControl.Page return reference to Page object contains this control.
Since you use another class for your page you must cast this property to
your page class:
For example
if your base page class named MyBasePage

((MyBasePage)MyUserControl.Page).[my base page property/method]

HTH

"Mikip" <mi***@plugthenet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I have some properties that are common to all pages so I have created a base class which every page inherits from. I now also want to use these
properties within User Controls on the page. Is there any way to get to
these properties through the parent property of the user control - I can't
seem to figure out how to get there. If I can't do this, do I have to do the same thing as the page and create a base user control class with the same
code in - Seems silly to have to execute the same code twice on a page?

Thanks in advance for any help

Mike

Nov 18 '05 #2

P: n/a
Anatoly,
Thanks for the reply...yes, if i maybe would have used a few more of my
limited neurons, I would have seen this! Incidently, do you think its better
to declare a private field in the UserControl class, do the cast once
assigning the base property to this field and use the private field within
the UserControl class. Will it save some performance not having to make the
cast everytime I want to use a base class property.?

Thx

Mike
"Anatoly" <an*****@hotmail.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
UserControl.Page return reference to Page object contains this control.
Since you use another class for your page you must cast this property to
your page class:
For example
if your base page class named MyBasePage

((MyBasePage)MyUserControl.Page).[my base page property/method]

HTH

"Mikip" <mi***@plugthenet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I have some properties that are common to all pages so I have created a

base
class which every page inherits from. I now also want to use these
properties within User Controls on the page. Is there any way to get to
these properties through the parent property of the user control - I can't seem to figure out how to get there. If I can't do this, do I have to do

the
same thing as the page and create a base user control class with the same code in - Seems silly to have to execute the same code twice on a page?

Thanks in advance for any help

Mike


Nov 18 '05 #3

P: n/a
Mike

In reality, this smells of bad design since your UserControl now is aware of
your Base Page Class and "talks" to it. Of course, if your UserControl and
base page are specific to this application then its not too bad.

Typically UserControls (like other controls) should be agnostic of the
specific page.

--
Shiv R. Kumar
http://www.matlus.com
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.