User Controls Inherited from a Custom Control share variables?

Y

Yuri Vanzine

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.
 
J

John Saunders

Yuri Vanzine said:
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?
 
Y

Yuri Vanzine

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

Yuri Vanzine

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top