473,770 Members | 7,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
<DefaultPropert y("SelectedValu e"), ToolboxData("<{ 0}:MyControl
runat=server></{0}:MyControl>" )> Public Class MyControl
Inherits System.Web.UI.W ebControls.WebC ontrol
Implements INamingContaine r

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)
EnsureChildCont rols()
sSelectedValue = Value
End Set

End Property

Protected Overrides Sub CreateChildCont rols()
popItems()
Controls.Add(dd lMyControl)
ddlMyControl.Au toPostBack = True
End Sub

Private Sub popItems()
Dim iItem as ListItem

iItem = New ListItem
iItem.Value = "A"
iItem.Text = "A Alpha"
ddlMyControl.It ems.Add(iItem)

iItem = New ListItem
iItem.Value = "B"
iItem.Text = "B Bravo"
ddlMyControl.It ems.Add(iItem)

iItem = New ListItem
iItem.Value = "C"
iItem.Text = "C Charlie"
ddlMyControl.It ems.Add(iItem)

End Sub

Public Sub ControlChanged( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles ddlMyControl.Se lectedIndexChan ged
SelectedValue = ddlMyControl.Se lectedValue
End Sub

End Class

In the aspx page:

<%@Register TagPrefix="enp" Namespace="eNPC ontrols2" Assembly="eNPCo ntrols2"
%>

....

<enp:eNPMyContr ol id=ENPMyControl 1 runat="server">
</enp:eNPMyContro l>

<asp:Label id=lblCtrl runat="server" Text="<%=eNPMyC ontrol.Selected Value%>">
</asp:Label>

Nov 19 '05 #1
1 1317
Additional info:

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

Me.lblCtrl.Text = Mme.ENPState1.S electedValue

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*********@eN etPortals.com> wrote in message
news:Qu******** ****@newsread2. news.atl.earthl ink.net...
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
<DefaultPropert y("SelectedValu e"), ToolboxData("<{ 0}:MyControl
runat=server></{0}:MyControl>" )> Public Class MyControl
Inherits System.Web.UI.W ebControls.WebC ontrol
Implements INamingContaine r

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)
EnsureChildCont rols()
sSelectedValue = Value
End Set

End Property

Protected Overrides Sub CreateChildCont rols()
popItems()
Controls.Add(dd lMyControl)
ddlMyControl.Au toPostBack = True
End Sub

Private Sub popItems()
Dim iItem as ListItem

iItem = New ListItem
iItem.Value = "A"
iItem.Text = "A Alpha"
ddlMyControl.It ems.Add(iItem)

iItem = New ListItem
iItem.Value = "B"
iItem.Text = "B Bravo"
ddlMyControl.It ems.Add(iItem)

iItem = New ListItem
iItem.Value = "C"
iItem.Text = "C Charlie"
ddlMyControl.It ems.Add(iItem)

End Sub

Public Sub ControlChanged( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles ddlMyControl.Se lectedIndexChan ged
SelectedValue = ddlMyControl.Se lectedValue
End Sub

End Class

In the aspx page:

<%@Register TagPrefix="enp" Namespace="eNPC ontrols2" Assembly="eNPCo ntrols2" %>

...

<enp:eNPMyContr ol id=ENPMyControl 1 runat="server">
</enp:eNPMyContro l>

<asp:Label id=lblCtrl runat="server" Text="<%=eNPMyC ontrol.Selected Value%>"> </asp:Label>

Nov 19 '05 #2

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

Similar topics

3
2784
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 some suitable default values in the tables. I note that although I can script the schema so that re-creating the structure of the database is simple on the users machine, I cannot script the contents of the tables also (automatically). What I would...
2
3182
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 problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
9
1528
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 from the control as follows: public string Text { get {
2
1228
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 control will be reflected on any page the control has been used on?
4
2024
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 datagrid isn't going to work). On this page, people can update a variet of records. On submit, I want to then go in and update all of the records. Normally, I'd make each form element include a runat: server and then declare it in my codebhind so I...
1
1532
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 composite server control, I'm trying to avoid having to build the control twice. Here's why this happens: The routine for building the control can be called from two places: (1) CreateChildControls, or (2) DataBind. If DataBind is called, it sets...
4
4090
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 initially configured during DataBind(). Thanks to Steven Cheng for pointing out that you have to set the constituent control properties after you add them to the composite control collection for the restore to work! However, I now have a...
4
2699
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 exposed properties of the constituent controls (e.g., they control how many constitutent controls are displayed). I am at a loss as to how to go about doing this. I have a custom designer for the control, but I don't see any functionality in the...
3
1949
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 Label and the TextBox are each rendered in one of the cells. Everything renders fine. The problem is that depending on the column the control represents I may want the textbox to be a different visible size during both design and runtime. I...
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10002
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.