Custom Controls created in WebControl are not EventBound

Discussion in 'ASP .Net Web Controls' started by Guest, Feb 17, 2005.

  1. Guest

    Guest Guest

    I am trying to figure out if there is something I am missing. Since i
    don't seem to have the wording I am really unable to to do much research.To
    sum the problem up EventBinding works for Button Controls when created
    inside a WebControl but the binding appears to be lost for any other
    control.


    When a control is dynamically added to a WebControl and a postback event
    is to be attached to it then usually the control must be created, given an
    ID, added to the control all within or before OnInit. Failing to do this
    results in viewstate problems and events not properly mapping back to their
    control.
    I have found this out by trial and error. However what I am unable to
    understand is why when these instructions are followed through for a Button
    the event is properly mapped back to the control's event handler upon a
    postback. However for controls such as a LinkButton and a ListBox they do
    not. I have AutoPostBack set to true. I give the control an ID, Add it to
    the Control's Control Collection and then attach the Event Handler.
    Now due to asp.net's insistence upon putting all webcontrols inside a
    span I have to override the Render method and I put everything inside my
    WholeContainer which happens to be a div usually. Not really crucial but
    just in case there is some subtlety or something asp.net does behind the
    scenes that is somehow connected.

    Now in my Init i have created 2 controls, 1 listbox and 1 Button.
    I have given both unique ID's and I have added both to the controls
    I have also attached event handlers to both.
    I have put code in both event handlers.
    Both controls are rendered at runtime
    Click the button and its EventHandler is mapped and it executes the
    proper code
    Select the Listbox and it posts back however the event is never mapped
    back and thus my EventHandler code is never triggered.
    What is missing from this? Why does the Button's PostBack event handler
    get mapped properly and not the ListBoxes.

    Thanks in advance.
     
    Guest, Feb 17, 2005
    #1
    1. Advertising

  2. Guest

    Guest Guest

    Never mind. It turns out that When EnableViewState is disabled for a
    listbox events are unable to be mapped back to it.

    <> wrote in message
    news:...
    > I am trying to figure out if there is something I am missing. Since i
    > don't seem to have the wording I am really unable to to do much
    > research.To sum the problem up EventBinding works for Button Controls when
    > created inside a WebControl but the binding appears to be lost for any
    > other control.
    >
    >
    > When a control is dynamically added to a WebControl and a postback
    > event is to be attached to it then usually the control must be created,
    > given an ID, added to the control all within or before OnInit. Failing to
    > do this results in viewstate problems and events not properly mapping back
    > to their control.
    > I have found this out by trial and error. However what I am unable to
    > understand is why when these instructions are followed through for a
    > Button the event is properly mapped back to the control's event handler
    > upon a postback. However for controls such as a LinkButton and a ListBox
    > they do not. I have AutoPostBack set to true. I give the control an ID,
    > Add it to the Control's Control Collection and then attach the Event
    > Handler.
    > Now due to asp.net's insistence upon putting all webcontrols inside a
    > span I have to override the Render method and I put everything inside my
    > WholeContainer which happens to be a div usually. Not really crucial but
    > just in case there is some subtlety or something asp.net does behind the
    > scenes that is somehow connected.
    >
    > Now in my Init i have created 2 controls, 1 listbox and 1 Button.
    > I have given both unique ID's and I have added both to the controls
    > I have also attached event handlers to both.
    > I have put code in both event handlers.
    > Both controls are rendered at runtime
    > Click the button and its EventHandler is mapped and it executes the
    > proper code
    > Select the Listbox and it posts back however the event is never mapped
    > back and thus my EventHandler code is never triggered.
    > What is missing from this? Why does the Button's PostBack event handler
    > get mapped properly and not the ListBoxes.
    >
    > Thanks in advance.
    >
    >
    >
     
    Guest, Feb 17, 2005
    #2
    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 Rae
    Replies:
    3
    Views:
    578
    =?Utf-8?B?amlt?=
    Sep 24, 2005
  2. =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=

    Dinamically created webcontrol does not fire events

    =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=, May 24, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    400
    =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=
    May 25, 2007
  3. Sunfire
    Replies:
    1
    Views:
    496
    Roland Dick
    Nov 10, 2007
  4. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    201
    Fabricio
    Sep 21, 2005
  5. Tim Greenwood

    HELP!! Dynamically created webcontrol not accessible on postback

    Tim Greenwood, May 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    182
    Brock Allen
    May 19, 2005
Loading...

Share This Page