THY02K
May 12th, 2005, 06:01 AM
Problem: Help! Custom Control ... event from child control not firing...?
I am building this custom control, which consists of the following child controls:
1. a textbox (txtSelectedOptionText)
2. a button (btnToggle)
3. a listbox (multi-select) (lstOptions)
4. a bunch of other controls (but not relevant to our discussion)
Basically, the button toggles visibility of the listbox via javascript. And the textbox display values selected in listbox in "comma-delimited" format. However, the problem is, I want to persist listbox selection in ViewState. I tried to do this by adding a handler to respond to onclick event for btnToggle (trying to retrieve selected options there, and put it in "ViewState"). For some reason the event handler is NEVER fired?!!? Any idea? When I had the debugger on... I can see: CreateChildControls() and Render() got fired but... none of my event handlers...???
Thanks in advance!
************************************************************
Here's the code:
Imports System.IO
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace application.ui.controls.webcontrols
<{0}:MultiSelectDropDown runat=server />")> Public Class MultiSelectDropDown
Inherits System.Web.UI.WebControls.WebControl
Protected txtSelectedOptionText As TextBox = New TextBox
Protected WithEvents btnToggle As ImageButton = New ImageButton
Protected lstOptions As ListBox = New ListBox
' other stuff...
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
'bunch of rendering...
Return
End Sub
Protected Overrides Sub CreateChildControls()
...
Controls.Add(txtSelectedOptionText)
Controls.Add(btnToggle)
...
Controls.Add(lstOptions)
...
MyBase.CreateChildControls()
End Sub
Protected Sub OnToggle(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnToggle.Click
'*** My intention is to retrieve option selected in lstOptions here and put it in ViewState... But this event handler is never fired???
Return
End Sub
End Class
End Namespace
I am building this custom control, which consists of the following child controls:
1. a textbox (txtSelectedOptionText)
2. a button (btnToggle)
3. a listbox (multi-select) (lstOptions)
4. a bunch of other controls (but not relevant to our discussion)
Basically, the button toggles visibility of the listbox via javascript. And the textbox display values selected in listbox in "comma-delimited" format. However, the problem is, I want to persist listbox selection in ViewState. I tried to do this by adding a handler to respond to onclick event for btnToggle (trying to retrieve selected options there, and put it in "ViewState"). For some reason the event handler is NEVER fired?!!? Any idea? When I had the debugger on... I can see: CreateChildControls() and Render() got fired but... none of my event handlers...???
Thanks in advance!
************************************************************
Here's the code:
Imports System.IO
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace application.ui.controls.webcontrols
<{0}:MultiSelectDropDown runat=server />")> Public Class MultiSelectDropDown
Inherits System.Web.UI.WebControls.WebControl
Protected txtSelectedOptionText As TextBox = New TextBox
Protected WithEvents btnToggle As ImageButton = New ImageButton
Protected lstOptions As ListBox = New ListBox
' other stuff...
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
'bunch of rendering...
Return
End Sub
Protected Overrides Sub CreateChildControls()
...
Controls.Add(txtSelectedOptionText)
Controls.Add(btnToggle)
...
Controls.Add(lstOptions)
...
MyBase.CreateChildControls()
End Sub
Protected Sub OnToggle(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnToggle.Click
'*** My intention is to retrieve option selected in lstOptions here and put it in ViewState... But this event handler is never fired???
Return
End Sub
End Class
End Namespace