I'm building a form in ASP.NET to send an email. So far things work great and I'm able to pass my ASP:TextBox contents to the email without any issue. Right now how I've done things is put in static text as the TB label and then follow it up with a TB control for the input.
Should I be using the ASP:Label control instead?
Code example:
<div>
Pub Contact Phone: <asp:TextBox ID="PublicationContactPhone" runat="server" TabIndex="9"></asp:TextBox>
</div>
Is there a form best practice that says to have all the non-input text as labels or is it preference?
This sounds like maybe a mixup of the ASP.NET <asp:Label>
control and the HTML <label>
element. For building forms it's a good practice to use the HTML <label>
for an input label so that clicking on the label will give the input element focus, you can implement a label two ways:
<label>A TextBox <input id="txtbox1" type="text" /></label>
)for
attribute on the label to the id
of the input (ex. <label for="txtbox1">A TextBox</label> <input id="txtbox1" type="text" />
)So you can markup your page like so and the text Pub Contact Phone:
will be clickable to give focus to the input
<div>
<label>
Pub Contact Phone:
<asp:TextBox ID="PublicationContactPhone" runat="server" TabIndex="9" />
</label>
</div>
You don't have to use the label control as the text is static. The label control is best used if you want to change the value of the static text in your code behind before the page is returned to the browser.
If you don't want to do this, then there is no need to use a label control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With