I have TextBox like below.
<asp:TextBox runat="server" ID="Name" value="aaaa" text="bbbb"/>
in code behind.
Dim str As String = Name.Text.Trim() ' value as bbbb
If I removed the text property.
<asp:TextBox runat="server" ID="Name" value="aaaa" /> <%--text="bbbb"--%>
Dim str As String = Name.Text.Trim() ' value as aaaa
whenever I am keeping text property I am not able to access Value field. How to get the value field when text property is present?
The TextBox server control is an input control that lets the user enter text. By default, the TextMode property of the control is set to TextBoxMode.
TextBox PropertiesTextAlign– for setting text alignment. ScrollBars– for adding scrollbars, both vertical and horizontal. Multiline– to set the TextBox Control to allow multiple lines. MaxLength– for specifying the maximum character number the TextBox Control will accept.
The TextBox control is used to create a text box where the user can input text.
Asp.Net Code document.getElementById('<%= txt_id.ClientID %>').value; The value property sets or returns the value of the value attribute of a text field. It contains the default value OR the value a user types in.
Don't use the value
property. If you are using asp.net's TextBox
you must use Text
.
When you add properties that don't exists in the TextBox class, asp.net will render those properties to the resulting html. So
<asp:TextBox runat="server" ID="Name" text="bbbb" mycustomproperty="hi" />
Will render to something like this
<input type="text" value="bbbb" id="..." name="..." mycustomproperty="hi"/>
If you omit the TextBox
's Text
property and write the value property, then the value property will be rendered.
<asp:TextBox runat="server" ID="Name" value="aaaa" />
To
<input type="text" value="aaaa" id="..." name="..."/>
TextBox doesn't has a Value property. When the TextBox instance is created, the HTML value property will be assigned to the Text property, and that's why you access the Text property it has the "aaaa" value.
Summary: Don't use value property when you use ASP.NET controls. Use the controls specific properties.
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