User Controls Inherited from a Custom Control share variables?

Discussion in 'ASP .Net Building Controls' started by Yuri Vanzine, Jul 2, 2004.

  1. Yuri Vanzine

    Yuri Vanzine Guest

    I have a Custom Control that I inherit from a User Control like this:

    public class SecureUserControl : UserControl, INamingContainer

    it maintains a few control states like visible, readonly relying on security settings.

    I override CreateChildControls() similar to how you woud handle a custom web control.

    Every User Control I design inherits from SecureUserControl and not from System.Web.UI.UserControl.

    The problem is that every time a private member is changed in one secureusercontrol-derived control, ie I change _readonly boolean member thru a button, the value in all the other secureusercontrol-derived controls changes also (I have 3 secureusercontrol-derived controls on the page and they end up sharing(???) the readonly property).

    In classic OOP, whatever happens to the object does not affect other objects, unless you are using a singleton class.

    My question to you, is UserControl class special or am I 'special' and do not understand how to apply oop to asp.net?

    Please help!

    P.S. I need to inherit from a UserControl and not from a WebControl or Control. The idea is to make your UserControls security-aware in one class and inherit from it.
    Yuri Vanzine, Jul 2, 2004
    #1
    1. Advertising

  2. "Yuri Vanzine" <Yuri > wrote in message
    news:...
    > I have a Custom Control that I inherit from a User Control like this:
    >
    > public class SecureUserControl : UserControl, INamingContainer
    >
    > it maintains a few control states like visible, readonly relying on

    security settings.
    >
    > I override CreateChildControls() similar to how you woud handle a custom

    web control.
    >
    > Every User Control I design inherits from SecureUserControl and not from

    System.Web.UI.UserControl.
    >
    > The problem is that every time a private member is changed in one

    secureusercontrol-derived control, ie I change _readonly boolean member thru
    a button, the value in all the other secureusercontrol-derived controls
    changes also (I have 3 secureusercontrol-derived controls on the page and
    they end up sharing(???) the readonly property).
    >
    > In classic OOP, whatever happens to the object does not affect other

    objects, unless you are using a singleton class.
    >
    > My question to you, is UserControl class special or am I 'special' and do

    not understand how to apply oop to asp.net?
    >
    > Please help!
    >
    > P.S. I need to inherit from a UserControl and not from a WebControl or

    Control. The idea is to make your UserControls security-aware in one class
    and inherit from it.

    Do you get the same effect when you inherit from WebControl?
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jul 2, 2004
    #2
    1. Advertising

  3. Yuri Vanzine

    Yuri Vanzine Guest

    I cannot test a webcontrol because the controls that inherit from secureusercontrol HAVE to be a usercontrol to be inherited by a ascx file.

    "John Saunders" wrote:

    > "Yuri Vanzine" <Yuri > wrote in message
    > news:...
    > > I have a Custom Control that I inherit from a User Control like this:
    > >
    > > public class SecureUserControl : UserControl, INamingContainer
    > >
    > > it maintains a few control states like visible, readonly relying on

    > security settings.
    > >
    > > I override CreateChildControls() similar to how you woud handle a custom

    > web control.
    > >
    > > Every User Control I design inherits from SecureUserControl and not from

    > System.Web.UI.UserControl.
    > >
    > > The problem is that every time a private member is changed in one

    > secureusercontrol-derived control, ie I change _readonly boolean member thru
    > a button, the value in all the other secureusercontrol-derived controls
    > changes also (I have 3 secureusercontrol-derived controls on the page and
    > they end up sharing(???) the readonly property).
    > >
    > > In classic OOP, whatever happens to the object does not affect other

    > objects, unless you are using a singleton class.
    > >
    > > My question to you, is UserControl class special or am I 'special' and do

    > not understand how to apply oop to asp.net?
    > >
    > > Please help!
    > >
    > > P.S. I need to inherit from a UserControl and not from a WebControl or

    > Control. The idea is to make your UserControls security-aware in one class
    > and inherit from it.
    >
    > Do you get the same effect when you inherit from WebControl?
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    >
    Yuri Vanzine, Jul 2, 2004
    #3
  4. Yuri Vanzine

    Yuri Vanzine Guest

    Thank you for your help. I found out that my woes had been caused by improper use of postback rather than variables being shared between several instances of a class. No further help needed.

    "Yuri Vanzine" wrote:

    > I cannot test a webcontrol because the controls that inherit from secureusercontrol HAVE to be a usercontrol to be inherited by a ascx file.
    >
    > "John Saunders" wrote:
    >
    > > "Yuri Vanzine" <Yuri > wrote in message
    > > news:...
    > > > I have a Custom Control that I inherit from a User Control like this:
    > > >
    > > > public class SecureUserControl : UserControl, INamingContainer
    > > >
    > > > it maintains a few control states like visible, readonly relying on

    > > security settings.
    > > >
    > > > I override CreateChildControls() similar to how you woud handle a custom

    > > web control.
    > > >
    > > > Every User Control I design inherits from SecureUserControl and not from

    > > System.Web.UI.UserControl.
    > > >
    > > > The problem is that every time a private member is changed in one

    > > secureusercontrol-derived control, ie I change _readonly boolean member thru
    > > a button, the value in all the other secureusercontrol-derived controls
    > > changes also (I have 3 secureusercontrol-derived controls on the page and
    > > they end up sharing(???) the readonly property).
    > > >
    > > > In classic OOP, whatever happens to the object does not affect other

    > > objects, unless you are using a singleton class.
    > > >
    > > > My question to you, is UserControl class special or am I 'special' and do

    > > not understand how to apply oop to asp.net?
    > > >
    > > > Please help!
    > > >
    > > > P.S. I need to inherit from a UserControl and not from a WebControl or

    > > Control. The idea is to make your UserControls security-aware in one class
    > > and inherit from it.
    > >
    > > Do you get the same effect when you inherit from WebControl?
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >
    > >
    Yuri Vanzine, Jul 2, 2004
    #4
    1. Advertising

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. Faizan Ahmed
    Replies:
    1
    Views:
    281
    John Saunders
    Jan 4, 2005
  2. Saraswati lakki
    Replies:
    0
    Views:
    1,321
    Saraswati lakki
    Jan 6, 2012
  3. Jack
    Replies:
    2
    Views:
    212
  4. 7stud --
    Replies:
    11
    Views:
    394
    7stud --
    Nov 9, 2007
  5. Eric Wong
    Replies:
    0
    Views:
    202
    Eric Wong
    Feb 13, 2010
Loading...

Share This Page