0

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 ?

PeteEngineer
  • 123
  • 4
  • 14

2 Answers2

1

try

$('<%:Control.ControlID%>').attr("disabled", true);
John x
  • 4,031
  • 8
  • 42
  • 67
  • i cannot comprehend what is not working, you need to provide more context to the "this is not working" – John x Jul 11 '12 at 06:17
  • does the selector return the correct element? have you checked it using firebug or any other DOM inspector ? are there any javascript related error? what version of .net you are using ? if its 4 then you can make the id of your control static ... – John x Jul 11 '12 at 06:19
0

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/

nbrooks
  • 18,126
  • 5
  • 54
  • 66