|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Multiple Label tags with same IDSorry 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? 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. -- Show quoteHide quoteTeemu 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? 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? > > > 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). -- Show quoteHide quoteTeemu Keiski ASP.NET MVP, AspInsider Finland, EU "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? >> >> >>
Why don't child control events trigger OnBubbleEvent?
Datalist - Image loads on localhost but not on server Valid values for properties Distributing OWC11 DropDownList selectedIndexChanged event not firing Datagrid Hyperlink Doubt Validation on dynamic fields Object reference not set to an instance of an object - newpost Programmatically Rotate Datagrid Rows checkboxlist help |
|||||||||||||||||||||||