views:

172

answers:

3

I want to render a <label> tag. But want to set some of it's properties while it's rendering like for and text value.

Actually my real problem is I want to associate a label with a radio button and this is the code so far I have:

<asp:RadioButton ID="Option4" GroupName="A" runat="server" />

<label for='<%=Option4.ClientID %>' id="lblOption4" runat="server">4</label>

But the problem with this code is that it is not working and rendering the for attibute's value as it is i.e. <%=Option4.ClientID %>. :-(

Is their any asp net server control which would render tag?

I don't want to set the Text property of the radio button due to some CSS limitations so plz do not give answers like why don't you set the Text property of the radio button.

+6  A: 

if this is .NET 2.0 or later, then use the ASP.NET LABEL control.

<asp:RadioButton ID="Option4" GroupName="A" runat="server" />
<asp:Label AssociatedControlId="Option4" Text="4" />
Stephen Wrighton
Thanks buddy. Worked like a charm....
Manish
A: 

If this is to ultimately handle accessiblity issues you could try the following tutorial: Creating an Accessible LABEL control in ASP.NET

Nicholas Murray