1

I'm working on My First ASP.NET Application. I have created some text boxes and buttons, and added client-side validation to the text boxes. I now wish to set and clear the enabled property of the buttons according to the contents and validity of the text boxes.

I have studied the questions and answers here, here, here and here, and the best I have been able to manage is this...

<script language="javascript" type="text/javascript">
    function SetButtonSensitivity()
    {
        var label = document.getElementById("<%= lblResult3.ClientID %>");
        var button = document.getElementById("<%= btnDone.ClientID %>");

        if (Page_ClientValidate())
        {
            label.Text = "valid";
            button.disabled = false;
        }
        else
        {
            label.Text = "not valid";
            button.disabled = true;
        }

    }
</script>

I can tell this script is invoked when I tab away from the textbox fields, as the error messages are emitted by the client-validate, but the script has no effect on the button or the label.

Can anyone see what I have overlooked?

4 Answers 4

3

You can't acces the Text property of a label from javascript. A label is rendered as a . You should try setting the innerHTML property:

label.innerHTML = "not valid";

Also use the javascript console to see what errors you have in your js code. (Ctrl+Shift+J in firefox)

Sign up to request clarification or add additional context in comments.

Comments

0

Try value attribute instead of Text

label.value = "valid";
button.disabled = false;

Comments

0

Well, since your Label is actually rendered as a <span> label.innerText = "valid"

Comments

0

You can use

label.innerHTML, label.innerText or label.value to get or set the text of the label.

"button.disabled = false/true" should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.