Experts: dynamic control events???

Discussion in 'ASP .Net' started by Assaf, May 11, 2004.

  1. Assaf

    Assaf Guest

    Hi all.

    In response to user selections, our app adds controls (buttons, image
    buttons) dynamically to a page with Controls.Add(myNewButtonControl).

    Now that we gotten on the page we want to make them do something for a
    living: how do we dynamically create events that the controls respond to?

    TEA for any pointers.

    - Assaf
     
    Assaf, May 11, 2004
    #1
    1. Advertising

  2. Assaf

    Natty Gur Guest

    Assaf hi,

    You need to attach methods on your page to controls events. if you using
    C# :
    MyControl.Click += new EventHandler(FunctionNameWithDelegartionSign(;

    VB:

    AddHandlerMyControl.Click , AddressOf FunctionNameWithDelegartionSign

    BUT! Event handler for dynamic control should be added before the page
    finish to build controls. in the page life cycle the Load event is the
    one that you can use.

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Natty Gur, May 12, 2004
    #2
    1. Advertising

  3. Assaf

    Assaf Guest

    Thanks a bunch Bin Song.

    One of the articles you listed revealed the missing part of the puzzle: I
    couldn't get the events for the dynamic control (which by the way is a
    custom composite control) to fire. What was missing was impmenting the
    System.Web.UI.INamingContainer interface on the control.

    - Assaf

    "Bin Song, MCP" <> wrote in message
    news:...
    > Hi,
    >
    > If you know the object type and name, see this:
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;317515
    > HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET
    > If Not,
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;311321
    > HOW TO: Dynamically Add a Control Without Hardcoding the Control Type in

    Visual Basic .NET
    >
    > Bin Song, MCP
     
    Assaf, May 12, 2004
    #3
  4. Assaf

    Assaf Guest

    Thanks for the pointer, Natty Guru.

    I think I accidentally bypassed the problem by implementing the dynamically
    added controls as custom composite controls. That way all the functionality
    is baked into the composite control's inner controls (e.g., the button
    control in the MyCustomCompositeControl control). I had to implement custom
    composites for other reason, of course, not just to get around this problem.

    - Assaf


    "Natty Gur" <> wrote in message
    news:%23ZpLxX%...
    > Assaf hi,
    >
    > You need to attach methods on your page to controls events. if you using
    > C# :
    > MyControl.Click += new EventHandler(FunctionNameWithDelegartionSign(;
    >
    > VB:
    >
    > AddHandlerMyControl.Click , AddressOf FunctionNameWithDelegartionSign
    >
    > BUT! Event handler for dynamic control should be added before the page
    > finish to build controls. in the page life cycle the Load event is the
    > one that you can use.
    >
    > Natty Gur[MVP]
    >
    > blog : http://weblogs.asp.net/ngur
    > Mobile: +972-(0)58-888377
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Assaf, May 12, 2004
    #4
    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. Replies:
    5
    Views:
    5,627
  2. =?Utf-8?B?S3Vt?=
    Replies:
    1
    Views:
    798
    Peter Blum
    Jun 8, 2005
  3. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    598
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  4. dje

    dynamic events on dynamic controls

    dje, Jun 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    137
    Robert Koritnik
    Jun 28, 2004
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    423
    Chris
    Aug 30, 2005
Loading...

Share This Page