Cannot enable disabled controls with client-side javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stu Carter

    #1

    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.getEle mentById("Recur sive_chk").disa bled = 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

    #2
    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@som ekindofcompany. co.uk> wrote in message
    news:#Dgu#MBXDH A.1644@TK2MSFTN GP10.phx.gbl...[color=blue]
    > 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[/color]
    post-back,[color=blue]
    > 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.getEle mentById("Recur sive_chk").disa bled = 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+
    >
    >[/color]


    Comment

    • Stu Carter

      #3
      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_c hk" style="Z-INDEX: 118; LEFT: 48px; POSITION:
      absolute; TOP: 488px" tabIndex="11" runat="server" CssClass="descr iption"
      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@visualso ft-inc.com> wrote in message
      news:ur#a8YBXDH A.208@tk2msftng p13.phx.gbl...> Hi,[color=blue]
      >
      > I dunno its a better way or not. but i suggest u to make the control[/color]
      disbale[color=blue]
      > 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[/color]
      server[color=blue]
      > side or onthe client side. that will work ...
      >
      > Regards
      >
      > Ahmed
      >
      > "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
      > news:#Dgu#MBXDH A.1644@TK2MSFTN GP10.phx.gbl...[color=green]
      > > 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[/color]
      > post-back,[color=green]
      > > I added some javascript to do this
      > >
      > > However, using client-side JS, I cannot enable any controls that have[/color][/color]
      been[color=blue][color=green]
      > > disabled by server-side code. If the control is initially enabled, I[/color][/color]
      can[color=blue][color=green]
      > > disable/enable it client-side.
      > >
      > > I'm using the following JS:
      > >
      > > document.getEle mentById("Recur sive_chk").disa bled = 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+
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • John Saunders

        #4
        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
        john.saunders@s urfcontrol.com

        "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
        news:OxFSZqBXDH A.1580@tk2msftn gp13.phx.gbl...[color=blue]
        > Hi Ahmed,
        >
        > Thanks for the reply.
        >
        > Yes, that would work with HTML controls, but I'm trying to enable a[/color]
        disabled[color=blue]
        > ASP.Net server side control...and thats the problem...
        >
        > e.g.
        > <asp:checkbox id="Recursive_c hk" style="Z-INDEX: 118; LEFT: 48px;[/color]
        POSITION:[color=blue]
        > absolute; TOP: 488px" tabIndex="11" runat="server" CssClass="descr iption"
        > Enabled="False" Text="Recursive ">
        >
        > That checkbox is disabled at design time/code behind, but I can't enable[/color]
        it[color=blue]
        > 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@visualso ft-inc.com> wrote in message
        > news:ur#a8YBXDH A.208@tk2msftng p13.phx.gbl...> Hi,[color=green]
        > >
        > > I dunno its a better way or not. but i suggest u to make the control[/color]
        > disbale[color=green]
        > > on design time..
        > > input id="cterdate" type="text" maxLength="12" size="20"[/color][/color]
        name="cterdate"[color=blue][color=green]
        > > runat="server" disabled
        > >
        > > Now you can change the status of the field on page load event on the[/color]
        > server[color=green]
        > > side or onthe client side. that will work ...
        > >
        > > Regards
        > >
        > > Ahmed
        > >
        > > "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
        > > news:#Dgu#MBXDH A.1644@TK2MSFTN GP10.phx.gbl...[color=darkred]
        > > > 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[/color][/color][/color]
        dynamically[color=blue][color=green][color=darkred]
        > > > enabled when the user checks a checkbox. Because I don't want a[/color]
        > > post-back,[color=darkred]
        > > > I added some javascript to do this
        > > >
        > > > However, using client-side JS, I cannot enable any controls that have[/color][/color]
        > been[color=green][color=darkred]
        > > > disabled by server-side code. If the control is initially enabled, I[/color][/color]
        > can[color=green][color=darkred]
        > > > disable/enable it client-side.
        > > >
        > > > I'm using the following JS:
        > > >
        > > > document.getEle mentById("Recur sive_chk").disa bled = 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+
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Stu Carter

          #5
          Re: Cannot enable disabled controls with client-side javascript

          John, it renders as:

          <span class="descript ion" disabled="disab led" style="Z-INDEX: 117; LEFT:
          48px; POSITION: absolute; TOP: 488px"><input id="Recursive_c hk"
          type="checkbox" name="Recursive _chk" disabled="disab led" 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:#7guKLDXDH A.3268@tk2msftn gp13.phx.gbl...[color=blue]
          > Stu,
          >
          > How does Recursive_chk render on the client? Could you show us the[/color]
          resulting[color=blue]
          > HTML?
          > --
          > John Saunders
          > Internet Engineer
          > john.saunders@s urfcontrol.com
          >
          > "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
          > news:OxFSZqBXDH A.1580@tk2msftn gp13.phx.gbl...[color=green]
          > > Hi Ahmed,
          > >
          > > Thanks for the reply.
          > >
          > > Yes, that would work with HTML controls, but I'm trying to enable a[/color]
          > disabled[color=green]
          > > ASP.Net server side control...and thats the problem...
          > >
          > > e.g.
          > > <asp:checkbox id="Recursive_c hk" style="Z-INDEX: 118; LEFT: 48px;[/color]
          > POSITION:[color=green]
          > > absolute; TOP: 488px" tabIndex="11" runat="server"[/color][/color]
          CssClass="descr iption"[color=blue][color=green]
          > > Enabled="False" Text="Recursive ">
          > >
          > > That checkbox is disabled at design time/code behind, but I can't enable[/color]
          > it[color=green]
          > > 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[/color][/color]
          controls[color=blue][color=green]
          > > to the HTML page and have that invoked when the page loads on the[/color][/color]
          client,[color=blue][color=green]
          > > but that just sucks!!
          > >
          > > Regards,
          > > Stuart
          > >
          > >
          > >
          > > "Ahmed Ali" <ahmed@visualso ft-inc.com> wrote in message
          > > news:ur#a8YBXDH A.208@tk2msftng p13.phx.gbl...> Hi,[color=darkred]
          > > >
          > > > I dunno its a better way or not. but i suggest u to make the control[/color]
          > > disbale[color=darkred]
          > > > on design time..
          > > > input id="cterdate" type="text" maxLength="12" size="20"[/color][/color]
          > name="cterdate"[color=green][color=darkred]
          > > > runat="server" disabled
          > > >
          > > > Now you can change the status of the field on page load event on the[/color]
          > > server[color=darkred]
          > > > side or onthe client side. that will work ...
          > > >
          > > > Regards
          > > >
          > > > Ahmed
          > > >
          > > > "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
          > > > news:#Dgu#MBXDH A.1644@TK2MSFTN GP10.phx.gbl...
          > > > > Hi,
          > > > >
          > > > > I have an aspx page where some controls are initially disabled by[/color][/color][/color]
          the[color=blue][color=green][color=darkred]
          > > > > code-behind 'Page_Load' event. I want these controls to be[/color][/color]
          > dynamically[color=green][color=darkred]
          > > > > 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[/color][/color][/color]
          have[color=blue][color=green]
          > > been[color=darkred]
          > > > > disabled by server-side code. If the control is initially enabled,[/color][/color][/color]
          I[color=blue][color=green]
          > > can[color=darkred]
          > > > > disable/enable it client-side.
          > > > >
          > > > > I'm using the following JS:
          > > > >
          > > > > document.getEle mentById("Recur sive_chk").disa bled = 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+
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Stu Carter

            #6
            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...<sha kes head>...ASP.Net
            is driving me nuts today! :)

            Thanks for your help Jon!
            Stu

            "John Saunders" <john.saunders@ surfcontrol.com > wrote in message
            news:uTBQIgDXDH A.1900@TK2MSFTN GP10.phx.gbl...[color=blue]
            > 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[/color]
            you[color=blue]
            > 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[/color]
            to[color=blue]
            > get to the parent of Recursive_chk to enable or disable it as well.
            > --
            > John Saunders
            > Internet Engineer
            > john.saunders@s urfcontrol.com
            >
            > "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
            > news:udeUUYDXDH A.2444@tk2msftn gp13.phx.gbl...[color=green]
            > > John, it renders as:
            > >
            > > <span class="descript ion" disabled="disab led" style="Z-INDEX: 117; LEFT:
            > > 48px; POSITION: absolute; TOP: 488px"><input id="Recursive_c hk"
            > > type="checkbox" name="Recursive _chk" disabled="disab led" 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:#7guKLDXDH A.3268@tk2msftn gp13.phx.gbl...[color=darkred]
            > > > Stu,
            > > >
            > > > How does Recursive_chk render on the client? Could you show us the[/color]
            > > resulting[color=darkred]
            > > > HTML?
            > > > --
            > > > John Saunders
            > > > Internet Engineer
            > > > john.saunders@s urfcontrol.com
            > > >
            > > > "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
            > > > news:OxFSZqBXDH A.1580@tk2msftn gp13.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_c hk" style="Z-INDEX: 118; LEFT: 48px;
            > > > POSITION:
            > > > > absolute; TOP: 488px" tabIndex="11" runat="server"[/color]
            > > CssClass="descr iption"[color=darkred]
            > > > > Enabled="False" Text="Recursive ">
            > > > >
            > > > > That checkbox is disabled at design time/code behind, but I can't[/color][/color]
            > enable[color=green][color=darkred]
            > > > 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[/color]
            > > controls[color=darkred]
            > > > > to the HTML page and have that invoked when the page loads on the[/color]
            > > client,[color=darkred]
            > > > > but that just sucks!!
            > > > >
            > > > > Regards,
            > > > > Stuart
            > > > >
            > > > >
            > > > >
            > > > > "Ahmed Ali" <ahmed@visualso ft-inc.com> wrote in message
            > > > > news:ur#a8YBXDH A.208@tk2msftng p13.phx.gbl...> Hi,
            > > > > >
            > > > > > I dunno its a better way or not. but i suggest u to make the[/color][/color][/color]
            control[color=blue][color=green][color=darkred]
            > > > > 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[/color][/color][/color]
            the[color=blue][color=green][color=darkred]
            > > > > server
            > > > > > side or onthe client side. that will work ...
            > > > > >
            > > > > > Regards
            > > > > >
            > > > > > Ahmed
            > > > > >
            > > > > > "Stu Carter" <Stu.Carter@som ekindofcompany. co.uk> wrote in message
            > > > > > news:#Dgu#MBXDH A.1644@TK2MSFTN GP10.phx.gbl...
            > > > > > > Hi,
            > > > > > >
            > > > > > > I have an aspx page where some controls are initially disabled[/color][/color][/color]
            by[color=blue][color=green]
            > > the[color=darkred]
            > > > > > > 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[/color]
            > > have[color=darkred]
            > > > > been
            > > > > > > disabled by server-side code. If the control is initially[/color][/color]
            > enabled,[color=green]
            > > I[color=darkred]
            > > > > can
            > > > > > > disable/enable it client-side.
            > > > > > >
            > > > > > > I'm using the following JS:
            > > > > > >
            > > > > > > document.getEle mentById("Recur sive_chk").disa bled = 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+
            > > > > > >
            > > > > > >
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Punisher

              #7
              Re: Cannot enable disabled controls with client-side javascript

              I figured it out for ya. Had the same problem

              use this

              //To Disable
              document.getEle mentById(strHid denCheckBox).pa rentElement.set Attribute('disa bled','true');


              //To Enable
              document.getEle mentById(strHid denCheckBox).pa rentElement.rem oveAttribute('d isabled');

              Comment

              Working...