0

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" />
4
  • Show us your code my friend. Commented May 21, 2014 at 9:57
  • this is my input: <input type="text" id="costCenterInput" data-isComboBox="true" data-datasourceName="costCenters" /> Commented May 21, 2014 at 10:00
  • You need to update your question, show us your C# code, in full if possible and your html in full if possible. Commented May 21, 2014 at 10:02
  • thank you Mr Gray: in server side I can get value by "String s = Request["costCenterInput"]", but how to get "data-datasourceName"? Commented May 21, 2014 at 10:15

3 Answers 3

1

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...

Sign up to request clarification or add additional context in comments.

2 Comments

thank you _Jamshid Asadzadeh_<br/>your answer is my case:<br/> i change the att in client side and i need to get the new value on server side<br/>runat="server" shows predefined attributes but not ay attributes<br/>can i get my att without hidden input?
As far as I know, No you can't! This is because http post method will send only field values. You can always set the hidden input's value before postback by JavaScript.
0

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);

1 Comment

Thank you securedeveloper, but my case is server-sice "c#" not client-side
0

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()

1 Comment

Thank You Mr Gray, It seems that this is only way, thank you for __doPostBack() again. ^_^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.