asp.net programmer
asp.net programmer

Reputation: 99

get specific attribute from html input

I can get value from html input by: Request["inputID"]

But, How to get data-myatt attribute from input below in server-side:

<input id="input1" type="text" value="value" data-myatt="my date" />

Upvotes: 0

Views: 1513

Answers (3)

Mr. Mr.
Mr. Mr.

Reputation: 4285

Why not create a hidden html input for your request to pass back to your code behind:

<input type="text" name="costCenterInput" data-isComboBox="true" />
<input type="hidden" name="costCenters" />

in your c#:

String costCenterInput = Request["costCenterInput"];
String costCenters = Request["costCenters"];

Or you can do some postback nastiness, see my answer here:

How to use __doPostBack()

Upvotes: 0

Afzal Ahmad
Afzal Ahmad

Reputation: 626

You can get input value by the following method,

 var input_value = document.getElementById('input1').value;

To get the specific attribute value you need,

var attribute_value = document.getElementById('input1').getAttribute('data-myatt');

or if you are using Jquery you can simply get attribute value by using,

$('#input1').attr('data-myatt);

Upvotes: 0

Jay
Jay

Reputation: 841

If you're using ASP.net web forms then all you have to do is to add the attribute runat="server" to the input tag, then you will have access to it and it's attributes.

If you changed the attribute on the client side and you want to have access to it on the server side, you'll have to put that data in another hidden input and get your value from there...

Upvotes: 1

Related Questions