0

I have two asp.net dropdownlists that I want to manipulate clientside with Javascript. These two dropdowns are inside a modal open: function()

When dropdown1.value == "me" I want dropdown2.value to be disabled

How can I accomplish this?

$(document).ready(function () {
                    if (document.getElementById('<%=dropdown1.ClientID%>').value == 'Me')
                        document.getElementById('<%=dropdown2.ClientID%>').disabled = true;
                    });

(optional) Part 2 I need to set an entity framework value to null after dropdown2 has been disabled how could I accomplish this without a postback?

1
  • 1
    If you're going to use jQuery, use it. Mixing your syntax just makes life difficult. Also, stick to asking 1 question per post. You're more likely to get it answered. Commented Sep 9, 2014 at 22:13

1 Answer 1

1

Part 1:

$(document).ready(function () 
{
   if($("#<%=dropdown1.ClientID%>").val() == "Me")
      $("#<%=dropdown2.ClientID%>").prop("disabled",true);
});

Part 2 :

You would need to make an ajax call to a code behind or webservice to do that.

.ASPX

$.ajax({
                type: "POST",
                url: "PageName.aspx/CodeBehindMethodName",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",

            success: function (result) {


            },
            error: function (error) {

            }
             });

.ASPX.CS

 [WebMethod]
        public static void Test()
        {
          // Call EF code
        }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your input I now have somewhere to go from your part 2. Part 1 still is not working unfortunately.
do you get any error ? Have you checked if the 1st dropdown has a value equals "Me" and not "ME" ?

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.