Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Updating a Control when a (different) Composite Control Changes

Reply
Thread Tools

Updating a Control when a (different) Composite Control Changes

 
 
Jeff
Guest
Posts: n/a
 
      03-21-2005
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>



 
Reply With Quote
 
 
 
 
Jeff
Guest
Posts: n/a
 
      03-21-2005
Additional info:

I've tried adding the following line to Page_Load event for the page:

Me.lblCtrl.Text = Mme.ENPState1.SelectedValue

When stepping through, it seems that the SelectedValue of the composite
control (ddlMyControl) gets set properly, but the SelectedValue of the
control on the aspx page (eNPMyControl) never gets set.

What am I missing?

- Jeff


"Jeff" <(E-Mail Removed)> wrote in message
news:QuF%d.385$(E-Mail Removed) et...
> 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>
>
>
>



 
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
Updating JTable Atomically - block data changes while updating. news.rcn.com Java 2 12-10-2007 11:49 AM
Composite Control: Changes not being stored on postback Mark Olbert ASP .Net 4 03-01-2006 03:50 PM
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
Composite control with dynamic composite controls sleigh ASP .Net 1 02-12-2004 06:24 PM



Advertisments