Adding User Control

Discussion in 'ASP .Net Building Controls' started by Slawek, Sep 11, 2003.

  1. Slawek

    Slawek Guest

    Hi everyone,
    I have a problem that I can't resolve. I have created a user control which
    is included in asp.net page (<@register...etc). All I need is to move this
    control from one place on the page to another(in Page_Load method). For
    example my control belongs to one cell (<td>) tag and I have to move it to
    another cell(<td>). In c# code I use <new tag>.Controls.Add(mycontrol) and
    it works perfect, accept that after moving control, all events for my
    control are fired twice(for example Load in my control and even pressing
    button in it). It looks like after adding control to new tag there is two
    instances of my control on the page. Because of this my application works
    improperly. I don't know how to fix it. Any suggestions ??

    Regards
    Slawek
     
    Slawek, Sep 11, 2003
    #1
    1. Advertising

  2. "Slawek" <> wrote in message
    news:...
    > Hi everyone,
    > I have a problem that I can't resolve. I have created a user control which
    > is included in asp.net page (<@register...etc). All I need is to move this
    > control from one place on the page to another(in Page_Load method). For
    > example my control belongs to one cell (<td>) tag and I have to move it to
    > another cell(<td>). In c# code I use <new tag>.Controls.Add(mycontrol) and
    > it works perfect, accept that after moving control, all events for my
    > control are fired twice(for example Load in my control and even pressing
    > button in it). It looks like after adding control to new tag there is two
    > instances of my control on the page. Because of this my application works
    > improperly. I don't know how to fix it. Any suggestions ??


    How about if you remove the control from the first cell before adding it to
    the second cell?
    --
    John Saunders
    Internet Engineer
     
    John Saunders, Sep 11, 2003
    #2
    1. Advertising

  3. Slawek

    Slawek Guest

    Add Command removes it from first control collection befor adding to the
    second one, but even if I do it myself it doesn't work. (The control is
    removed - id doesn't appear on the page twice, but it receives all events
    two times)


    "John Saunders" <> wrote in message
    news:...
    > "Slawek" <> wrote in message
    > news:...
    > > Hi everyone,
    > > I have a problem that I can't resolve. I have created a user control

    which
    > > is included in asp.net page (<@register...etc). All I need is to move

    this
    > > control from one place on the page to another(in Page_Load method). For
    > > example my control belongs to one cell (<td>) tag and I have to move it

    to
    > > another cell(<td>). In c# code I use <new tag>.Controls.Add(mycontrol)

    and
    > > it works perfect, accept that after moving control, all events for my
    > > control are fired twice(for example Load in my control and even pressing
    > > button in it). It looks like after adding control to new tag there is

    two
    > > instances of my control on the page. Because of this my application

    works
    > > improperly. I don't know how to fix it. Any suggestions ??

    >
    > How about if you remove the control from the first cell before adding it

    to
    > the second cell?
    > --
    > John Saunders
    > Internet Engineer
    >
    >
    >
     
    Slawek, Sep 12, 2003
    #3
  4. Interesting. Perhaps you could remove the event handlers before removing the
    control?
    --
    John Saunders
    Internet Engineer
     
    John Saunders, Sep 12, 2003
    #4
  5. Slawek

    Slawek Guest

    But how can I do it?? All events for my control are raised for two times.
    For example if there is a button in that control and I've button_click()
    method in code - it'll by called twice :(

    Regards
    Slawek

    "John Saunders" <> wrote in message
    news:...
    > Interesting. Perhaps you could remove the event handlers before removing

    the
    > control?
    > --
    > John Saunders
    > Internet Engineer
    >
    >
    >
     
    Slawek, Sep 12, 2003
    #5
    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. Tom Rowton
    Replies:
    2
    Views:
    681
    Tom Rowton
    Aug 1, 2003
  2. Mad Scientist Jr
    Replies:
    0
    Views:
    659
    Mad Scientist Jr
    Mar 22, 2006
  3. Replies:
    1
    Views:
    737
    Sean Chambers
    Oct 11, 2006
  4. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    568
    Jonathan Wood
    Feb 2, 2010
  5. Travis Pruitt

    Dynamically Adding User Control with Child User Control

    Travis Pruitt, Jan 13, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    193
    Travis Pruitt
    Jan 13, 2005
Loading...

Share This Page