Hi -
I am developing a composite control using VB.NET.
In the ASP.NET page using the control, How can I update a label text value
to reflect the value of a property of the custom control whenever the
composite control is changed? The label is not a part of the custom
control.
I've managed to correctly set the composite control properties whenever it
is changed, but I don't know how or where to update the label.
What am I doing wrong?
My code is below. Thanks for your help.
- Jeff
<DefaultProperty("SelectedValue"), ToolboxData("<{0}:MyControl
runat=server></{0}:MyControl>")> Public Class MyControl
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim WithEvents ddlMyControl as New DropDownList
Dim sSelectedValue as String
<Bindable(True), Category("Data"), DefaultValue("A")> Property
[SelectedValue]() As String
Get
Return sSelectedValue
End Get
Set(ByVal Value As String)
EnsureChildControls()
sSelectedValue = Value
End Set
End Property
Protected Overrides Sub CreateChildControls()
popItems()
Controls.Add(ddlMyControl)
ddlMyControl.AutoPostBack = True
End Sub
Private Sub popItems()
Dim iItem as ListItem
iItem = New ListItem
iItem.Value = "A"
iItem.Text = "A Alpha"
ddlMyControl.Items.Add(iItem)
iItem = New ListItem
iItem.Value = "B"
iItem.Text = "B Bravo"
ddlMyControl.Items.Add(iItem)
iItem = New ListItem
iItem.Value = "C"
iItem.Text = "C Charlie"
ddlMyControl.Items.Add(iItem)
End Sub
Public Sub ControlChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ddlMyControl.SelectedIndexChanged
SelectedValue = ddlMyControl.SelectedValue
End Sub
End Class
In the aspx page:
<%@Register TagPrefix="enp" Namespace="eNPControls2" Assembly="eNPControls2"
%>
....
<enp:eNPMyControl id=ENPMyControl1 runat="server">
</enp:eNPMyControl>
<asp:Label id=lblCtrl runat="server" Text="<%=eNPMyControl.SelectedValue%>">
</asp:Label>