Cannot enable disabled controls with client-side javascript

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Cannot enable disabled controls with client-side javascript

    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+


    Stu Carter Guest

  2. Similar Questions and Discussions

    1. enable debugging from the client side
      How do you enable debugging so that people see it from the client side? I have gone in to properties, clicked on edit www service, clicked on the...
    2. Hit Counter in Javascript on client side.
      Have opportunity to use free web server space but can only use client scripting. How to code hit counter in javascript? Any help would be...
    3. Controls with a client side onLoad function or seting a cursor server side
      Is there any way to create a web control that calls a client side onLoad function? Its diffucilt since you are not able to access the form or...
    4. Loading client-side images for use in Javascript
      Ok, I'll play the dumb guy.... if your script is running on the server under the testapp application, why isn't the source 'Images/down.gif' (Path...
    5. how can i add client side javascript to a web user control?
      hi, i have a web user control that i wish to add some client-side javascript to. something like this: onChange="javascript:DoSomething();" ...
  3. #2

    Default Re: Cannot enable disabled controls with client-side javascript

    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

    "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    news:#Dgu#MBXDHA.1644@TK2MSFTNGP10.phx.gbl...
    > 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+
    >
    >

    Ahmed Ali Guest

  4. #3

    Default Re: Cannot enable disabled controls with client-side javascript

    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



    "Ahmed Ali" <ahmed@visualsoft-inc.com> wrote in message
    news:ur#a8YBXDHA.208@tk2msftngp13.phx.gbl...> 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
    >
    > "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    > news:#Dgu#MBXDHA.1644@TK2MSFTNGP10.phx.gbl...
    > > 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+
    > >
    > >
    >
    >

    Stu Carter Guest

  5. #4

    Default Re: Cannot enable disabled controls with client-side javascript

    Stu,

    How does Recursive_chk render on the client? Could you show us the resulting
    HTML?
    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]

    "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    news:OxFSZqBXDHA.1580@tk2msftngp13.phx.gbl...
    > 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
    >
    >
    >
    > "Ahmed Ali" <ahmed@visualsoft-inc.com> wrote in message
    > news:ur#a8YBXDHA.208@tk2msftngp13.phx.gbl...> 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
    > >
    > > "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    > > news:#Dgu#MBXDHA.1644@TK2MSFTNGP10.phx.gbl...
    > > > 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+
    > > >
    > > >
    > >
    > >
    >
    >

    John Saunders Guest

  6. #5

    Default Re: Cannot enable disabled controls with client-side javascript

    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

    "John Saunders" <john.saunders@surfcontrol.com> wrote in message
    news:#7guKLDXDHA.3268@tk2msftngp13.phx.gbl...
    > Stu,
    >
    > How does Recursive_chk render on the client? Could you show us the
    resulting
    > HTML?
    > --
    > John Saunders
    > Internet Engineer
    > [email]john.saunders@surfcontrol.com[/email]
    >
    > "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    > news:OxFSZqBXDHA.1580@tk2msftngp13.phx.gbl...
    > > 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
    > >
    > >
    > >
    > > "Ahmed Ali" <ahmed@visualsoft-inc.com> wrote in message
    > > news:ur#a8YBXDHA.208@tk2msftngp13.phx.gbl...> 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
    > > >
    > > > "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    > > > news:#Dgu#MBXDHA.1644@TK2MSFTNGP10.phx.gbl...
    > > > > 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+
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Stu Carter Guest

  7. #6

    Default Re: Cannot enable disabled controls with client-side javascript

    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

    "John Saunders" <john.saunders@surfcontrol.com> wrote in message
    news:uTBQIgDXDHA.1900@TK2MSFTNGP10.phx.gbl...
    > Stu,
    >
    > You may have hit the nail on the head. As an experiment, try putting that
    > code into your .aspx file as raw HTML (changing the name and id of the
    > checkbox, of course). And see if your JavaScript can enable it. I bet if
    you
    > remove the disabled attribute from the span, it will work.
    >
    > All of which _still_ leaves you in trouble, but at least you'll know what
    > kind of trouble you're it! Your JavaScript code would have to use the DOM
    to
    > get to the parent of Recursive_chk to enable or disable it as well.
    > --
    > John Saunders
    > Internet Engineer
    > [email]john.saunders@surfcontrol.com[/email]
    >
    > "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    > news:udeUUYDXDHA.2444@tk2msftngp13.phx.gbl...
    > > 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
    > >
    > > "John Saunders" <john.saunders@surfcontrol.com> wrote in message
    > > news:#7guKLDXDHA.3268@tk2msftngp13.phx.gbl...
    > > > Stu,
    > > >
    > > > How does Recursive_chk render on the client? Could you show us the
    > > resulting
    > > > HTML?
    > > > --
    > > > John Saunders
    > > > Internet Engineer
    > > > [email]john.saunders@surfcontrol.com[/email]
    > > >
    > > > "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    > > > news:OxFSZqBXDHA.1580@tk2msftngp13.phx.gbl...
    > > > > 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
    > > > >
    > > > >
    > > > >
    > > > > "Ahmed Ali" <ahmed@visualsoft-inc.com> wrote in message
    > > > > news:ur#a8YBXDHA.208@tk2msftngp13.phx.gbl...> 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
    > > > > >
    > > > > > "Stu Carter" <Stu.Carter@somekindofcompany.co.uk> wrote in message
    > > > > > news:#Dgu#MBXDHA.1644@TK2MSFTNGP10.phx.gbl...
    > > > > > > 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+
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Stu Carter Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139