Home All Groups Group Topic Archive Search About

Multiple Label tags with same ID

Author
10 May 2005 3:11 PM
Paul
Sorry for a very newbie question but...

I make a database call to get a label called X.

I then try the same label tag twice on the same page such as:

<asp:label id="X" runat="server" />
<asp:label id="X" runat="server" />

I get an error saying "The ID 'X' is already used by another control."

Can't I use multiple label tag references to the same ID?

Author
10 May 2005 5:18 PM
Teemu Keiski
Hi,

inside a naming container on a page (Page itself and container controls) one
server-side control can have one ID and it is unique to that control,
otherwise framework cannot distinguise them (controls) from each other.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU


Show quoteHide quote
"Paul" <P***@discussions.microsoft.com> wrote in message
news:7BFDA0D7-69DA-478F-BC73-199C4DD3FA2E@microsoft.com...
> Sorry for a very newbie question but...
>
> I make a database call to get a label called X.
>
> I then try the same label tag twice on the same page such as:
>
> <asp:label id="X" runat="server" />
> <asp:label id="X" runat="server" />
>
> I get an error saying "The ID 'X' is already used by another control."
>
> Can't I use multiple label tag references to the same ID?
Author
11 May 2005 5:06 PM
Paul
Does this then mean that if I wanted to the same piece of text in 2 places on
the page, then I would have to use to different label names and simply set
the the .text property of each label equal to the same extracted piece of
text?



Show quoteHide quote
"Teemu Keiski" wrote:

> Hi,
>
> inside a naming container on a page (Page itself and container controls) one
> server-side control can have one ID and it is unique to that control,
> otherwise framework cannot distinguise them (controls) from each other.
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
>
>
> "Paul" <P***@discussions.microsoft.com> wrote in message
> news:7BFDA0D7-69DA-478F-BC73-199C4DD3FA2E@microsoft.com...
> > Sorry for a very newbie question but...
> >
> > I make a database call to get a label called X.
> >
> > I then try the same label tag twice on the same page such as:
> >
> > <asp:label id="X" runat="server" />
> > <asp:label id="X" runat="server" />
> >
> > I get an error saying "The ID 'X' is already used by another control."
> >
> > Can't I use multiple label tag references to the same ID?
>
>
>
Author
13 May 2005 4:15 PM
Teemu Keiski
If you need to use Labels, then yes.

If the need is just to output the text, you could also have one member
variable in code (or code-behind file), which  you set to have certain text.
In aspx you could take this out by using <%=variablename%> (it is outputted
when page is rendered), so that you don't need to keep the text in two
places.

There's just the catch that member variables do not keep their state on
postback, so it could complicate thimgs (create a Vproperty utilizing
Viewstate etc, to overcome it, and render the property straight).

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

Show quoteHide quote
"Paul" <P***@discussions.microsoft.com> wrote in message
news:89881842-B4DE-43E4-BAE9-8B23B27A4311@microsoft.com...
> Does this then mean that if I wanted to the same piece of text in 2 places
> on
> the page, then I would have to use to different label names and simply set
> the the .text property of each label equal to the same extracted piece of
> text?
>
>
>
> "Teemu Keiski" wrote:
>
>> Hi,
>>
>> inside a naming container on a page (Page itself and container controls)
>> one
>> server-side control can have one ID and it is unique to that control,
>> otherwise framework cannot distinguise them (controls) from each other.
>>
>> --
>> Teemu Keiski
>> ASP.NET MVP, AspInsider
>> Finland, EU
>>
>>
>> "Paul" <P***@discussions.microsoft.com> wrote in message
>> news:7BFDA0D7-69DA-478F-BC73-199C4DD3FA2E@microsoft.com...
>> > Sorry for a very newbie question but...
>> >
>> > I make a database call to get a label called X.
>> >
>> > I then try the same label tag twice on the same page such as:
>> >
>> > <asp:label id="X" runat="server" />
>> > <asp:label id="X" runat="server" />
>> >
>> > I get an error saying "The ID 'X' is already used by another control."
>> >
>> > Can't I use multiple label tag references to the same ID?
>>
>>
>>