0

I am using ASP.net and have a dropdown control.

 <asp:DropdownList runat="server" ID = "fieldReadOnlyContent" Enabled="false" class = "attribute"><asp:ListItem value = "0">False</asp:ListItem><asp:ListItem value = "1">True</asp:ListItem></asp:DropdownList>

I wanted to adjust the dropdown control via the clientside controls qith jquery. I get the value which it needs to be set to.

//d[3] will be either true or false.
$("#fieldReadOnlyContent").val(d[3]);

the above attempt didnt seem to set the item to properly enabled. HOw would i do this?

0

3 Answers 3

2

Try this:

$("#<%=fieldReadOnlyContent.ClientID%>").val(d[3]);
Sign up to request clarification or add additional context in comments.

1 Comment

this will work but you will no longer be able to dynamically add/modify controls onthe page, if that where required...
1

The item is not getting set because $("#fieldReadOnlyContent").val(d[3]); will check for the value.

For your case

if(d[3]=='false'){
 $("#fieldReadOnlyContent").val('0');
}
else
{
 $("#fieldReadOnlyContent").val('1');
}

3 Comments

im going to test this out quick.
this is the correct answer from what it looks. Thank you very much Clyde
@Fallenreaper : No issues. I had got into the same problem a week ago. Hence I knew what was the issue
0

fieldReadOnlyContent is not necessarily the ID given to the client-side HTML element.

You can use ClientIDMode="Static" server-side to control the client-side ID in .net4.0 (source), or <%= fieldReadOnlyContent.ClientID %> to inject the client id directly into the javascript otherwise.

Comments

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.