Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access custom Textbox attributes in ASP.Net?

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?

like image 338
Jeffrey Blake Avatar asked Oct 08 '12 16:10

Jeffrey Blake


People also ask

How to add TextBox in razor page?

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.

What is TextBox control in asp net?

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.

Which property of TextBox is used to change behavior of the control in asp net?

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.


1 Answers

This is tested and worked

string customAttrDataDefault = TXT_LenderName.Attributes["data-default"];
txtpassword.Attributes.Add("value","Password value");
like image 147
Adil Avatar answered Oct 19 '22 22:10

Adil