Cannot enable disabled controls with client-side javascript

S

Stu Carter

Hi,

I have an aspx page where some controls are initially disabled by the
code-behind 'Page_Load' event. I want these controls to be dynamically
enabled when the user checks a checkbox. Because I don't want a post-back,
I added some javascript to do this

However, using client-side JS, I cannot enable any controls that have been
disabled by server-side code. If the control is initially enabled, I can
disable/enable it client-side.

I'm using the following JS:

document.getElementById("Recursive_chk").disabled = false;

Is this a known problem, or am I doing something wrong?

Thanks,
Stuart

Env: Windows 2003, VS. Net 2003, 1.1 Framework, IE 6+
 
A

Ahmed Ali

Hi,

I dunno its a better way or not. but i suggest u to make the control disbale
on design time..
input id="cterdate" type="text" maxLength="12" size="20" name="cterdate"
runat="server" disabled

Now you can change the status of the field on page load event on the server
side or onthe client side. that will work ...

Regards

Ahmed
 
S

Stu Carter

Hi Ahmed,

Thanks for the reply.

Yes, that would work with HTML controls, but I'm trying to enable a disabled
ASP.Net server side control...and thats the problem...

e.g.
<asp:checkbox id="Recursive_chk" style="Z-INDEX: 118; LEFT: 48px; POSITION:
absolute; TOP: 488px" tabIndex="11" runat="server" CssClass="description"
Enabled="False" Text="Recursive">

That checkbox is disabled at design time/code behind, but I can't enable it
using client-side script. And I don't want to revert to using HTML
controls, as its a step backwards. :)

My only other thought is to move the logic for enabling/disabling controls
to the HTML page and have that invoked when the page loads on the client,
but that just sucks!!

Regards,
Stuart
 
J

John Saunders

Stu,

How does Recursive_chk render on the client? Could you show us the resulting
HTML?
 
S

Stu Carter

John, it renders as:

<span class="description" disabled="disabled" style="Z-INDEX: 117; LEFT:
48px; POSITION: absolute; TOP: 488px"><input id="Recursive_chk"
type="checkbox" name="Recursive_chk" disabled="disabled" tabindex="11"
/><label for="Recursive_chk">Recursive</label></span>

Hmm, is the span taking precedence over the checkbox? ASP.Net emits the
<span>

Cheers,
Stu
 
S

Stu Carter

Yes, said nail is now bent; it's the bloody <span>!

ASP.Net should not be setting the span to disabled, since it is completely
redundant - the checkbox renders itself disabled...<shakes head>...ASP.Net
is driving me nuts today! :)

Thanks for your help Jon!
Stu
 
P

Punisher

I figured it out for ya. Had the same problem

use this

//To Disable
document.getElementById(strHiddenCheckBox).parentElement.setAttribute('disabled','true');


//To Enable
document.getElementById(strHiddenCheckBox).parentElement.removeAttribute('disabled');
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top