Session-Object for more than 1 user control?

Discussion in 'ASP .Net' started by Frank Schumacher, Nov 4, 2004.

  1. 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
     
    Frank Schumacher, Nov 4, 2004
    #1
    1. Advertising

  2. 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:]


    "Frank Schumacher" <-leipzig.de> wrote in message
    news:...
    > 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
     
    Angelos Karantzalis, Nov 4, 2004
    #2
    1. Advertising

  3. Hello Angelo,

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

    Ciao,
    Frank
     
    Frank Schumacher, Nov 15, 2004
    #3
    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. momo898
    Replies:
    2
    Views:
    511
    bruce barker \(sqlwork.com\)
    Oct 12, 2006
  2. lds
    Replies:
    0
    Views:
    395
  3. Sinan Alkan
    Replies:
    0
    Views:
    433
    Sinan Alkan
    Oct 3, 2008
  4. Steven D'Aprano
    Replies:
    0
    Views:
    133
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    107
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page