shared problem (user control)[2005]
hi all. i used key word shared in my control for declaire some variable. when i used this control in form. if i only create a control, it does not matter. But if i create 2 controls(the same form), all of field that i used variable shared, will be same. i mean duplicate data in field. can i avoid this problem?
many thank for your help
Re: shared problem (user control)[2005]
If you don't want to duplicate the data then why don't you create instance variable?
Re: shared problem (user control)[2005]
A lot of people seem to think that the Shared key word is just a convenience to allow you to access a member without referencing a specific instance. It's not. A Shared member is a member of the class, not an object of that type. There is only ever one class, no matter how many instances you create, so there's only ever one value for a Shared field or property. Do NOT use Shared fields or properties as a convenience. That's a hack. ONLY declare a member Shared if it logically IS a member of the class. If it's not, as yours obviously is not, then don't declare it Shared. Declare it as a regular instance member and access it via a reference to the appropriate instance.