Access Custom HTML Attributes

I want to know if there is a way to add a custom attribute to a HTML element.

For instance,

<input type="text" name="txtNAME1" displayName="dname1" /> 

In the above example, the custom attribute "displayName" is not a standard HTML attribute. So I want to know if I can determine the same thing and click on a given value on the server and access the same attribute value.

Thanks in advance!

+4
source share
1 answer

What language do you use? You can do it in C # using

 <input type="text" name="txtNAME1" displayName="dname1" runat="server" id="test" /> 

Then in the code behind:

 test.Attributes["displayName"]; 

You can also access it in jQuery with

 $('test').attr('displayName') 

and send it to the server through the handler.

+4
source

Source: https://habr.com/ru/post/1344570/


All Articles