Disable TextBox from server-side?

Last post 08-29-2008 3:21 PM by RobSil. 3 replies.

Sort Posts:

  • Disable TextBox from server-side?

    08-29-2008, 1:00 PM
    • Member
      68 point Member
    • RobSil
    • Member since 07-03-2008, 12:20 PM
    • Posts 136

    Hey all,

    I have a field that contains an 'optional' passcode.   Above that I have the "On/Off" radio buttons that enable/disable the field.  Client-side it's no problem to have the field be disabled or enabled based upon what the user selects (via javascript below).  But now I want to add the ability to 'update' the settings.  so I load out of the database the users details and am trying to use the code-behind to enable or disable the text field.  It does not seem to work as I would assume.

     

    Javascript:

        <script type="text/javascript">
                <!--
                    function setPassCodeEnabled(){
                        document.getElementById("<%=passCodeTB.ClientID%>").disabled = false;
                    }

                    function setPassCodeDisabled(){
                        document.getElementById("<%=passCodeTB.ClientID%>").disabled = true;
                    }
                //-->
            </script>

     

    This script is called from the radio buttons and works fine.

     

    Code-Behind:

       if (bIsSecure)

             passCodeTB.Enabled = true;

    else  

              passCodeTB.Enabled = false;

     

    I am not sure why that .Enabled approach will not work, but the text box stays disabled despite me verifying that it is indeed being set to true.  Can anyone help me sort this out please?

     

    Thx,

    Rob

     

     

  • Re: Disable TextBox from server-side?

    08-29-2008, 2:12 PM
    • Contributor
      2,240 point Contributor
    • MajorCats
    • Member since 08-30-2002, 1:13 PM
    • Kansas City, MO USA
    • Posts 456

    This is just a long shot...but what is your radiobutton defaulted to?  Is it defaulted to "off"?  Could it be that when the page builds, it is running your javascript when it sets the default value of the radiobutton.

     Put an alert('Passcode enabled!'); in your function so you can see if your javascript is being executed.  If it is, you can try to move your code for settign passcodetb or you could set the radiobutton selection as appropriate instead (which would run the javascript to enable/disable).

    MajorCats
  • Re: Disable TextBox from server-side?

    08-29-2008, 2:13 PM
    • Contributor
      2,240 point Contributor
    • MajorCats
    • Member since 08-30-2002, 1:13 PM
    • Kansas City, MO USA
    • Posts 456

    This is just a long shot...but what is your radiobutton defaulted to?  Is it defaulted to "off"?  Could it be that when the page builds, it is running your javascript when it sets the default value of the radiobutton.

     Put an alert('Passcode enabled!'); in your function so you can see if your javascript is being executed.  If it is, you can try to move your code for settign passcodetb or you could set the radiobutton selection as appropriate instead (which would run the javascript to enable/disable).

    MajorCats
  • Re: Disable TextBox from server-side?

    08-29-2008, 3:21 PM
    • Member
      68 point Member
    • RobSil
    • Member since 07-03-2008, 12:20 PM
    • Posts 136

     Thanks Major... I tried that (actually had deleted those form the sample code before posting).  I did manage to solve it... i swear each time I make a post I find the answer myself soon thereafter.

     

    The issue was that I had the disabled being set in the HTML code also... so I was actually setting it, then unsetting it before the entire page was returned to the client.  I removed that auto-populate and now I set/unset properly.

     

     

Page 1 of 1 (4 items)