473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Updating a Control when a (different) Composite Control Changes

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>

Nov 19 '05 #1
1 1300
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" <je*********@eNetPortals.com> wrote in message
news:Qu************@newsread2.news.atl.earthlink.n 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>

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
9
by: Alphonse Giambrone | last post by:
I have built a simple composite control that consists of a textbox, requiredfieldvalidator and rangevalidator. For properties that are unique to the individual control, I set/get them directly...
2
by: Mark Goldin | last post by:
In order to maintain my composite controls I will need to modify them from time to time. Are there special requirements for composite controls development to make sure that any change to composite...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
1
by: dasein fiasco | last post by:
I'm sure this is a design question that is commonly encountered, but I can't find any resources which explain how to solve it. I would deeply appreciate any advice. Basically, when building a...
4
by: Mark Olbert | last post by:
This involves a family of related, databound ASPNET2 composite controls. I've managed to arrange things so that the composite controls restore themselves from ViewState on postback after they're...
4
by: Mark Olbert | last post by:
I've written a composite custom control which I would like to have update its design-time display when one of several properties changes at design time. These custom properties are not simply the...
3
by: Eric | last post by:
I have created a fairly basic composite control consisting of a Label and a TextBox. In the overridden Render function, I'm creating a table with two rows and each row contains a cell (td). The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.