cannot access a control

HLRosenberger used Ask the Experts™
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 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??

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If ctl00_PageContent_btnSave__Button is actually the rendered ID then you don't need to wrap it in ASP tags. You should be able to simply reference it via:

var btn= document.getElementById("ctl00_PageContent_btnSave__Button");



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");
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Try this:



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

Following an 'Objection' by Tomarse111 (at 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,
Community Support Moderator

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial