Handling Events For Dynamically Created Buttons

Discussion in 'ASP .Net' started by Nathan Sokalski, Feb 25, 2008.

  1. I have LinkButtons that are dynamically created in one of the PostBack
    events. They must be created in the PostBack event because one of the
    variables required to determine which ones to create comes from the event
    arguments. Because the LinkButtons are not created in the Init event, they
    will not exist when I click them to perform a postback. How do I handle the
    events for these LinkButtons? I appreciate any help you can give. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Feb 25, 2008
    #1
    1. Advertising

  2. Nathan Sokalski

    Masudur Guest

    On Feb 25, 11:38 am, "Nathan Sokalski" <> wrote:
    > I have LinkButtons that are dynamically created in one of the PostBack
    > events. They must be created in the PostBack event because one of the
    > variables required to determine which ones to create comes from the event
    > arguments. Because the LinkButtons are not created in the Init event, they
    > will not exist when I click them to perform a postback. How do I handle the
    > events for these LinkButtons? I appreciate any help you can give. Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    Hi...

    Once you have created the controls... constract a viewstate variable
    or session variable to that you can know that dynamically created
    links are exists...
    After each post back "on Init" first determine wheither dynamically
    added controls exists or not... if exists do create the dynamically
    added links again...
    asp.net will automatically map the event and fire it...
    but make sure the control ids remain same...


    Masudur
    www.munna.shatkotha.com
    www.shatkotha.com
     
    Masudur, Feb 25, 2008
    #2
    1. Advertising

  3. That would be fine if the number of dynamically created LinkButtons had a
    maximum, but it doesn't. Therefore, I would not know how many to create in
    the Init event. Also, is there any site you can give me that has a good
    example of how to do this? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Masudur" <> wrote in message
    news:...
    > On Feb 25, 11:38 am, "Nathan Sokalski" <> wrote:
    >> I have LinkButtons that are dynamically created in one of the PostBack
    >> events. They must be created in the PostBack event because one of the
    >> variables required to determine which ones to create comes from the event
    >> arguments. Because the LinkButtons are not created in the Init event,
    >> they
    >> will not exist when I click them to perform a postback. How do I handle
    >> the
    >> events for these LinkButtons? I appreciate any help you can give. Thanks.
    >> --
    >> Nathan Sokalski
    >> ://www.nathansokalski.com/

    >
    > Hi...
    >
    > Once you have created the controls... constract a viewstate variable
    > or session variable to that you can know that dynamically created
    > links are exists...
    > After each post back "on Init" first determine wheither dynamically
    > added controls exists or not... if exists do create the dynamically
    > added links again...
    > asp.net will automatically map the event and fire it...
    > but make sure the control ids remain same...
    >
    >
    > Masudur
    > www.munna.shatkotha.com
    > www.shatkotha.com
     
    Nathan Sokalski, Feb 26, 2008
    #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. Mark
    Replies:
    3
    Views:
    531
    Mark Rae
    Jan 8, 2007
  2. Amoril
    Replies:
    5
    Views:
    511
    Amoril
    Feb 21, 2007
  3. msimmons
    Replies:
    0
    Views:
    544
    msimmons
    Jul 16, 2009
  4. Kasabaarde Sumta

    events for dynamically created buttons nested in custom control

    Kasabaarde Sumta, Oct 29, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    179
    Kasabaarde Sumta
    Oct 29, 2004
  5. Nathan Sokalski

    Handling Events For Dynamically Created Buttons

    Nathan Sokalski, Feb 25, 2008, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    171
    Nathan Sokalski
    Feb 26, 2008
Loading...

Share This Page