Session-Object for more than 1 user control?

  • Thread starter Frank Schumacher
  • Start date
F

Frank Schumacher

Hi NG,

I have another problem with User controls. Thanks to your help I was
finaly able to create a Control, which is doing what I want it to do.

But now I want to add more than one User-Control to my WebForm.
Unfortunatly, my UserControl is using the Session-Variable to store some
values I need for each roundtrip. The problem is, that *each*
UserControl uses the same name for the Session-Variable.
I tried to add the instance-name of the Control to the Session-Variable
name to distinguish between the different UserControls, but I have no
clue, how to get this name.
The onClick-function is sending an object (sender) which I thought I
could use for. I tried to Cast it to System.Web.UI.UserControl, but this
has no name-property. Any ideas about this?

Oh well, and a second thing: I want to add the ucs dynamically. But how
can I then call the functions of my uc, for I have no variable at design
time.

Thanks in advance,
Frank
 
A

Angelos Karantzalis

Although your last name gives me bad Sunday morning memories ....

I think you can solve both your problems at once ...

Dynamically creating your controls and adding them to the page, requires at
least one variable:

MyControl objInstance = (MyControl )Activator.CreateInstance(blah-blah); //
or something similar

Now, if you add a public Id property to the MyControl class, your next line
could be:

objInstance.Id = controlIndex; // Where control index is some sort of unique
Id ...

.... add the control to a Hashtable - also a member variable of your class -
with the Id as the key ... and voila! ;] you now have a referece to the
instance of the control by Id, AND you have a unique identifier to use in
your session key.

Hope that pointed to the right direction ...
Angel
O:]
 
F

Frank Schumacher

Hello Angelo,

thanks for the head ups, they pointed me in the right direction.

Ciao,
Frank
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top