Custom Controls created in WebControl are not EventBound

G

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.
 
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top