Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > error: can't find control 'mylabel'

Reply
Thread Tools

error: can't find control 'mylabel'

 
 
Ben
Guest
Posts: n/a
 
      08-18-2006
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>

<aspropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
</aspropDownList>

Thanks
Ben


 
Reply With Quote
 
 
 
 
Marina Levit [MVP]
Guest
Posts: n/a
 
      08-18-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>
>
> <aspropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
> </aspropDownList>
>
> Thanks
> Ben
>



 
Reply With Quote
 
 
 
 
Ben
Guest
Posts: n/a
 
      08-18-2006
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>
<asparameter Name="name" Type="String" />
<asp:ControlParameter ControlID="dropdownlist1" Name="pl"
PropertyName="SelectedValue" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

<aspetailsView 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>
<aspropDownList ID="DropDownList1"
runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="place DataValueField="placel">
</aspropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
</aspetailsView>

asp:SqlDataSource ID="SqlDataSource2"
....


"Marina Levit [MVP]" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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>
>>
>> <aspropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
>> </aspropDownList>
>>
>> Thanks
>> Ben
>>

>
>



 
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
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
cannot find control within control Daves ASP .Net 5 09-09-2008 11:46 PM
Find Control in user control Chris ASP .Net 2 06-05-2007 06:56 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM



Advertisments