PeteEngineer
PeteEngineer

Reputation: 113

Changing the control Id to variable

I need to change the below code:

 $("#ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_btnAdd").attr("disabled", true);

To this:

var ControlID = "#ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_btnAdd"

$(ControlID).attr("disabled", true);

But the above one not working .. what is the error ?

Upvotes: 0

Views: 293

Answers (2)

nbrooks
nbrooks

Reputation: 18233

I suspect it isn't working in either case. Use .prop() instead of .attr(), to disable the element.

var ControlID = "#ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_btnAdd"
$(ControlID).prop("disabled", true);

Properties generally affect the dynamic state of a DOM element without changing the serialized HTML attribute. Examples include the value property of input elements, the disabled property of inputs and buttons, or the checked property of a checkbox. The .prop() method should be used to set disabled and checked instead of the .attr() method. The .val() method should be used for getting and setting value.

Source: http://api.jquery.com/prop/

Upvotes: 0

John x
John x

Reputation: 4031

try

$('<%:Control.ControlID%>').attr("disabled", true);

Upvotes: 1

Related Questions