473,320 Members | 1,870 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,320 software developers and data experts.

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.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:TemplateField>
<ItemTemplate>
<asp:Label ID="mylabel" Runat="server"
Text='<%# Bind("field1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
</asp:DropDownList>

Thanks
Ben
Aug 18 '06 #1
2 2188
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.nowrote in message
news:eB**************@TK2MSFTNGP06.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:TemplateField>
<ItemTemplate>
<asp:Label ID="mylabel" Runat="server"
Text='<%# Bind("field1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
</asp:DropDownList>

Thanks
Ben

Aug 18 '06 #2
Ben
Thanks for replying.
This is bad news for me, because i defined an InsertItemTemplate containing
a dropdownlist with the possible values into the detailsview (put into
insert mode) .
Result: the Controlparameter can't find controlID="dropdownlist1".
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:SqlDataSource ID="SqlDataSource1"
...
InsertCommand="INSERT INTO [pc] ([name], [place]) VALUES (?, ?, @pl)"
"OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb">
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:ControlParameter ControlID="dropdownlist1" Name="pl"
PropertyName="SelectedValue" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

<asp:DetailsView ID="DetailsView1" runat="server" DataKeyNames="pcnr"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<Fields>
<asp:BoundField DataField="pcnr" HeaderText="pcnr"
ReadOnly="True"
<asp:BoundField DataField="name" />
<asp:TemplateField >
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1"
runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="place DataValueField="placel">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>

asp:SqlDataSource ID="SqlDataSource2"
....
"Marina Levit [MVP]" <so*****@nospam.comschreef in bericht
news:%2****************@TK2MSFTNGP06.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.nowrote in message
news:eB**************@TK2MSFTNGP06.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:TemplateField>
<ItemTemplate>
<asp:Label ID="mylabel" Runat="server"
Text='<%# Bind("field1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
</asp:DropDownList>

Thanks
Ben


Aug 18 '06 #3

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

Similar topics

6
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...
0
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...
0
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...
1
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...
4
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">...
9
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
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...
7
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()...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.