Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Custom Controls created in WebControl are not EventBound

Reply
Thread Tools

Custom Controls created in WebControl are not EventBound

 
 
Guest
Posts: n/a
 
      02-17-2005
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.



 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      02-17-2005
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.
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
databound custom controls vs composite databound custom controls rodchar ASP .Net 0 11-26-2007 03:51 PM
aspnet.mdf file still is created even though i created a custom provider? Sunfire ASP .Net 1 11-10-2007 04:30 AM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
VS2005 ASP.NET 2.0 does not fire event for dynamically created custom web controls Amelyan ASP .Net 2 11-05-2005 05:29 PM
Custom webcontrol that references another webcontrol Fabricio ASP .Net Building Controls 0 09-21-2005 02:55 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57