1

I have one control with some asp form elements, but how do I get the form elements in my other control. I usually do jQuery('#<%= MyDropDownList.ClientID %>).val(), but this is not possible since it is in the other control. How do I access the element without hardcoding it?

So to sum it up: Control 1: Asp:DropDownList Control 2: Needs access to the value in the asp:DropDownlist from control 1 through jQuery.

2 Answers 2

1

If the names are unique, you can use the selector does name matching on the end of the id.

$('[id$="DropDownList1"]').val();

This will match all controls whose id ends with DropDownList1 and get the value of the first one. If the name is unique, then it will be your other dropdown list.

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

Comments

1

You can get value for the dropdown inside Control1 using the the following jQuery selector.

$('#<%= Control1.ClientID%> select').val()

2 Comments

I know the value inside control1 can be get by the code you wrote, but what if I want it from control 2?
I am assuming that both controls are in the same page and the jQuery is part of the page. If the jQuery is part of each individual control, then you may to assign a unique CssClass property to the dropdown in Control1 that you can uniquely identify it from Control2.

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.