Should I use an ASP: Label tag?

I am creating a form in ASP.NET to send email. So far, everything is working fine, and I can transfer the contents of ASP: TextBox to e-mail without any problems. Right now, as I did things, it is put as static text as a TB label, and then do it with the TB control for input.

Should I use an ASP: Label control?

Code example:

<div> Pub Contact Phone: <asp:TextBox ID="PublicationContactPhone" runat="server" TabIndex="9"></asp:TextBox> </div> 

Is there a best practice that says that all texts not in the text are shortcuts or preferred?

+4
source share
3 answers

This is like mixing an ASP.NET <asp:Label> control and an HTML <label> element. To build forms, itโ€™s good practice to use HTML <label> for the input label, so clicking on the label will give focus to the element, you can implement the label in two ways:

  • put static text and input in the label together (for example <label>A TextBox <input id="txtbox1" type="text" /></label> )
  • put static text in the label and set the for attribute to the label on the id for input (for example, <label for="txtbox1">A TextBox</label> <input id="txtbox1" type="text" /> )

This way, you can layout your page like this and the text of Pub Contact Phone: will be available for interactive input.

 <div> <label> Pub Contact Phone: <asp:TextBox ID="PublicationContactPhone" runat="server" TabIndex="9" /> </label> </div> 
+5
source

You do not need to use a label control as the text is static. The label control is best used if you want to change the value of static text in your code before the page returns to the browser.

If you do not want to do this, then there is no need to use a label control.

+3
source

I personally donโ€™t like things that complicate the code .

Do you need to change the contents of shortcuts in code?

If so, use the Label control because it is easy to change it in encoding ... otherwise just write the text there.

+2
source

All Articles