Reputation: 5597
How can I get ClientSide(JavaScript) Value for My ASP.net Custom Control?
for example I want to get a value like this:
var selectedItemID = getElementById("<%=MyControl1.ClientId%>").value;
How can i set a specific Value in my control scripts to get it from ".value
" property like above?
Additional Note: i want ".value" property(javascript) to get the dropDown control(one of my controls in my custom control) selected Value.
Upvotes: 0
Views: 7303
Reputation: 971
You can have a custom attribute for your custom control while it is rendering and bind the necessary value. Then in the Clientside, you can get the custom attribute and get the corresponding value from it.
For ex: Say suppose you are adding a custom attribute to your control using the code below while rendering,
MyControl.Attribures.Add("attributeName","Value");
then you can get the value in the clientside using the code snippet below.
var controlValue = $("#"+"<%= MyControl1.ClientID %>").attr("attributeName");
This would give you the value that you stored in the custom attribute of the control.
Upvotes: 1
Reputation: 68922
If your control rendered as an input, your code will work but if it is anything else, such as a span or label, you need to use .innerHTML
instead of .value
Upvotes: 0
Reputation: 1639
just do like this way using jquery:
$("<%= MyControl1.ClientID %>").val();
using javascript:
var Val=document.getelementbyid("<%= MyControl1.ClientID %>").value;
hope this help.
Upvotes: 0
Reputation: 3559
I'm not sured but You can try this:
var control = $find("<%= MyControl1.ClientID %>");
may be following link usefull for you No error message displayed for custom validator
Upvotes: 0