473,705 Members | 6,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error: can't find control 'mylabel'

Ben
Hi,

In the code-behind, i can refer to the dropdownlist defined in the aspx file
with this (e.g.)
dropdownlist1.s ekectedvalue = ...

but why can i not refer to the label defined in the TemplateField in the
same aspx file like below?
This gives the error: "can't find control 'mylabel' ":
mylabel.text="o k"

<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label ID="mylabel" Runat="server"
Text='<%# Bind("field1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

<asp:DropDownLi st ID="dropdownlis t1" runat="server" AutoPostBack="T rue" >
</asp:DropDownLis t>

Thanks
Ben
Aug 18 '06 #1
2 2194
Because it is just a template. If there are 20 rows, there will be 20
labels. If there are 50 rows, there will be 50 labels.
So which one could 'myLabel' possibly refer to? How would the page know
which one of the unknown number of labels that will be created youw ant?

It can't.

"Ben" <sd**@sdscs.now rote in message
news:eB******** ******@TK2MSFTN GP06.phx.gbl...
Hi,

In the code-behind, i can refer to the dropdownlist defined in the aspx
file with this (e.g.)
dropdownlist1.s ekectedvalue = ...

but why can i not refer to the label defined in the TemplateField in the
same aspx file like below?
This gives the error: "can't find control 'mylabel' ":
mylabel.text="o k"

<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label ID="mylabel" Runat="server"
Text='<%# Bind("field1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

<asp:DropDownLi st ID="dropdownlis t1" runat="server" AutoPostBack="T rue" >
</asp:DropDownLis t>

Thanks
Ben

Aug 18 '06 #2
Ben
Thanks for replying.
This is bad news for me, because i defined an InsertItemTempl ate containing
a dropdownlist with the possible values into the detailsview (put into
insert mode) .
Result: the Controlparamete r can't find controlID="drop downlist1".
How can i put the selectedvalue of the dropdownlist into that template field
for inserting the new record?

Thanks again
Ben

See part of code:

<asp:SqlDataSou rce ID="SqlDataSour ce1"
...
InsertCommand=" INSERT INTO [pc] ([name], [place]) VALUES (?, ?, @pl)"
"OldValuesParam eterFormatStrin g="original_{0} "
ProviderName="S ystem.Data.OleD b">
<InsertParamete rs>
<asp:Paramete r Name="name" Type="String" />
<asp:ControlPar ameter ControlID="drop downlist1" Name="pl"
PropertyName="S electedValue" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>

<asp:DetailsVie w ID="DetailsView 1" runat="server" DataKeyNames="p cnr"
DataSourceID="S qlDataSource1" DefaultMode="In sert">
<Fields>
<asp:BoundFie ld DataField="pcnr " HeaderText="pcn r"
ReadOnly="True"
<asp:BoundFie ld DataField="name " />
<asp:TemplateFi eld >
<InsertItemTemp late>
<asp:DropDownLi st ID="DropDownLis t1"
runat="server" AutoPostBack="T rue" DataSourceID="S qlDataSource2"
DataTextField=" place DataValueField= "placel">
</asp:DropDownLis t>
</InsertItemTempl ate>
</asp:TemplateFie ld>
<asp:CommandFie ld ShowInsertButto n="True" />
</Fields>
</asp:DetailsView >

asp:SqlDataSour ce ID="SqlDataSour ce2"
....
"Marina Levit [MVP]" <so*****@nospam .comschreef in bericht
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Because it is just a template. If there are 20 rows, there will be 20
labels. If there are 50 rows, there will be 50 labels.
So which one could 'myLabel' possibly refer to? How would the page know
which one of the unknown number of labels that will be created youw ant?

It can't.

"Ben" <sd**@sdscs.now rote in message
news:eB******** ******@TK2MSFTN GP06.phx.gbl...
>Hi,

In the code-behind, i can refer to the dropdownlist defined in the aspx
file with this (e.g.)
dropdownlist1. sekectedvalue = ...

but why can i not refer to the label defined in the TemplateField in the
same aspx file like below?
This gives the error: "can't find control 'mylabel' ":
mylabel.text=" ok"

<asp:TemplateF ield>
<ItemTemplat e>
<asp:Label ID="mylabel" Runat="server"
Text='<%# Bind("field1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

<asp:DropDownL ist ID="dropdownlis t1" runat="server" AutoPostBack="T rue" >
</asp:DropDownLis t>

Thanks
Ben


Aug 18 '06 #3

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

Similar topics

6
4749
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
0
1175
by: Andrew | last post by:
Can someone out there help. I am using Server. Transfer from a user control to a webform and tried to follow many examples exactly as specified but cannot get around the (Specified cast is not valid.) ERROR which happens on the second page Search.aspx on the line with (PrevPageValues = (FirstPage)Context.Handler;). I have also got <%@ Reference Page="_FirstPage.ascx" %> at the top of the second page.
0
1040
by: Robson Carvalho Machado | last post by:
Dear Friends, I have the following code that creates dynamic controls at my form. My dificult is how to correct this code to put distinct AddHandler to each button and how to choose what label will receive text when Button1 is clickedor Button2 is clicked. I want to make possible to change text on Label1 when Button1 is clicked and change text on Label2 when Button2 is clicked .. and so on...
1
1222
by: Davíð Þórisson | last post by:
Trying to migrate from ASP... been scratching my head for almost 12 hours now on this task that should be so easy, wtf can't I access the asp:label control from my .cs code??? It returns no errors but simply no text is inserted... I have 3 pages; *** default.aspx *** <%@ Register TagPrefix="UserControls" TagName="Initializer" Src="initializer.ascx" %> <UserControls:Initializer runat="server" />
4
8996
by: Harry | last post by:
Hello, I have a Repeater control that contains a Label control inside its ItemTemplate. A dummy mockup of the HTML code looks as follows: <asp:repeater id="StyleRepeater" Runat="server"> <ItemTemplate> <asp:Label ID="ClassLabel" Runat="server"> <... various other ASP.NET Web Controls ...> </ItemTemplate> </asp:repeater>
9
6097
by: Sarfaraz Khan | last post by:
Hello, anyone can guid me how we can handle and define control array in vb.net? Thanks & regards SARFARAZ KHAN
1
2789
by: Steve Hershoff | last post by:
I'm using VS 2003, and need to extract the text from an asp label in my code-behind file. The label is part of a DataList's ItemTemplate. I've noticed that in my ascx file (we're using User Controls here) I can't set the Text property in the opening tag when writing out the <asp:Label....</asp:Labeltags. I have to put my text between the opening and closing tags, like you would with a regular HTML tag. So this might be the cause of...
7
1296
by: olds350racer | last post by:
I am a newbie but have come across a question I hope someone can help with. Given the following code for a UserControl: ' Declares in the class Private intCount as Interger Private myLabel() as Label ' Code in the Load event of my UserControl Dim xCount as Integer intCount = 10
0
1202
by: murtyin | last post by:
Hi to All, I created one ClassLibrary in .Net using VB.Net, which is configured for COM InterOP. In this Library, I created 3 classes and below they are. (1) Document class: which is having 2 properties (a) AddPage : function for adding a Page to the Document. (b) DrawToFile : method which 'll draw the output to the specified file. (2) Page class: Having a AddLabel function used for adding a Label to the Page. (3) Label...
0
8768
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
9274
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...
0
9139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9034
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
8979
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
6606
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
5933
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();...
0
4704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2083
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.