Access pages base class properties from User Control

Discussion in 'ASP .Net' started by Mikip, Jan 18, 2004.

  1. Mikip

    Mikip Guest

    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
     
    Mikip, Jan 18, 2004
    #1
    1. Advertisements

  2. Mikip

    Anatoly Guest

    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" <> wrote in message
    news:%...
    > 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
    >
    >
     
    Anatoly, Jan 18, 2004
    #2
    1. Advertisements

  3. Mikip

    Mikip Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:%...
    > > 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
    > >
    > >

    >
    >
     
    Mikip, Jan 18, 2004
    #3
  4. Mikip

    Shiv Kumar Guest

    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
     
    Shiv Kumar, Jan 18, 2004
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davíð Þórisson

    access the base Page class from user controls??

    Davíð Þórisson, Oct 26, 2004, in forum: ASP .Net
    Replies:
    10
    Views:
    1,075
    Davíð Þórisson
    Oct 28, 2004
  2. oliviers
    Replies:
    3
    Views:
    828
    oliviers
    Feb 15, 2007
  3. Alf P. Steinbach
    Replies:
    6
    Views:
    808
    John Carson
    Sep 3, 2005
  4. Max2006
    Replies:
    2
    Views:
    622
    Max2006
    Jul 13, 2007
  5. Chris Zopers

    Access user control from other user control

    Chris Zopers, Feb 20, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    724
    Nanda Lella[MSFT]
    Apr 27, 2009
  6. Hicham Mouline
    Replies:
    1
    Views:
    822
    Victor Bazarov
    Apr 20, 2009
  7. Hans Östlund
    Replies:
    1
    Views:
    288
    Alessandro Zifiglio
    Feb 5, 2004
  8. Karan Rajput
    Replies:
    2
    Views:
    301
    Abinoam Jr.
    Dec 22, 2010
Loading...