Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

cannot access a control

I am successfully referencing other controls on my page like this:

var category = document.getElementById("<%= lstCategory.ClientID %>");

However, this does not work for my SAVE button.  

var btn= document.getElementById("<%= btnSave.ClientID %>");
alert(btn)

Alert displays "null".

So, I displayed the source after the page is rendered.  And this is the ID for the SAVE button:  ctl00_PageContent_btnSave__Button

So, I did this:

var btn= document.getElementById("<%= ctl00_PageContent_btnSave__Button.ClientID %>");

But this fails at runtime with the following error:

'ctl00_PageContent_btnSave__Button' is not declared.

So, if the declared ID is different than the generated ID, how does one reference this control via Javascript??

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Tomarse111
Tomarse111
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HLRosenberger

ASKER

That's it!  alert(btn) is not null.   Thanks.

 Now, I want to disable this button.  But this does not seem to work.

btn.disabled = true;

Any idea why, or what I'm doing wrong?
I think it should work:

Your method is right to get reference of a control with server tags like:
var btn= document.getElementById("<%= btnSave.ClientID %>");

As it doesn't work, try this...

var btn = document.getElementById("ctl00_PageContent_btnSave");
alert(btn);
Try this:

btn.disabled="disabled";
or
btn.disabled="true";
I never got this to work.
Technically I answered your question correctly, as you confirmed in your response (ID 35771380). You then asked a new question which was not correctly answered. Therefore, unfortunately, I will be objecting.
This question is answered, please stop request for attention
All,
 
Following an 'Objection' by Tomarse111 (at https://www.experts-exchange.com/questions/27052278/25-May-11-11-Automated-Request-for-Review-Objection-to-Delete-Q-27041077.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
_alias99
Community Support Moderator