I am using/abusing CSS classes and custom html attributes to provide default data to a set of textboxes. The code-front for this looks like the following (with some supporting javascript to handle checking/setting the default data when the field is blank):
<asp:TextBox ID="TXT_LenderName" class='defaultText' data-default='Institution Name' runat="server"></asp:TextBox>
This works.
I am working on the code-behind to process this form. I would like to be able to compare the value of the TXT_LenderName.Text
to the value of the data-default
attribute, but I haven't been able to find a way to get the value of a custom html attribute. Suggestions?
Create a Textbox in ASP.NET MVCThe HtmlHelper class includes two extension methods TextBox() and TextBoxFor<TModel, TProperty>() that renders the HTML textbox control <input type="text"> in the razor view.
ASP.NET Web Forms TextBox. This is an input control which is used to take user input. To create TextBox either we can write code or use the drag and drop facility of visual studio IDE. This is server side control, asp provides own tag to create it.
By default, the TextMode property of the control is set to TextBoxMode. SingleLine , which displays a single-line text box. However, you can also use the TextBox control to display a multiline text box or a text box that masks user input by changing the value of the TextMode property to TextBoxMode.
This is tested and worked
string customAttrDataDefault = TXT_LenderName.Attributes["data-default"];
txtpassword.Attributes.Add("value","Password value");
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