How to use the

后端 未结 8 2123

How can I use the tag within an ASP.NET application? I want it to be valid, accessible, and usable.

I understand the optimal HTML way is t

相关标签:
8条回答
  • 2020-12-01 03:09

    I use <asp:Label ... AssociatedControlID="Username" ...> controls for this. They get rendered as <label> tags and set the for attribute appropriately.

    Note that you can also nest other tags within the Label control if you wish:

    <asp:Label ID="UsernameLabel"
               Text="Username:"
               AssociatedControlID="UsernameTextBox"
               runat="server">
        <asp:TextBox ID="UsernameTextBox" runat="server" />
    </asp:Label>
    
    0 讨论(0)
  • 2020-12-01 03:10

    I guess the easiest way to do it is this.

    <asp:Label AssociatedControlID="Username" runat="server" Text="Username:"></asp:Label>
    <asp:TextBox ID="Username" runat="server"></asp:TextBox>
    
    0 讨论(0)
  • 2020-12-01 03:10
    <p><asp:Label ID="label1"           Text="Username:"           AssociatedControlID="txtUserName"           runat="server">    <asp:TextBox ID="txtUserName" runat="server" /></asp:Label></p>
    
    0 讨论(0)
  • If you want a label, but don't have another control to use in AssociatedControlID one can use the label itself

    <asp:Label ID="Not_Span" AssociatedControlID="Not_Span" Text="Will be rendered as label" />
    
    0 讨论(0)
  • 2020-12-01 03:16

    You my also try and this:

    <asp:Label  ID="Label1" runat="server" Text="label"></asp:Label>
    

    This is what Visual Studio, or any other software gives you if you drag and drop a label.

    0 讨论(0)
  • 2020-12-01 03:22

    You can also write it like this:

    <label for="<%= Username.ClientID %>">Username:</label>
    <asp:TextBox ID="Username" runat="server" />
    

    Phil Haack has a blog post on this topic

    0 讨论(0)
提交回复
热议问题