views:

597

answers:

1

I'm trying to validate a multiline textbox control as follows:

My content page (I'm using master pages) contains a text box control with a custom validator:

    <asp:TextBox ID="IssueDescription" TextMode="MultiLine" 
    Columns="40" Rows="5" runat="server" CssClass="textbox">
    </asp:TextBox>
<asp:CustomValidator ID="IssueDescValidator" runat="server" 
ErrorMessage="Please select a valid option" 
ClientValidationFunction="IssueDescValidation" 
ControlToValidate="IssueDescription"></asp:CustomValidator>

I'm using ClientValidationFunction property to do javascript validation. The javascript looks as follows:

private static string IssueDescValidator() {
    string issuedescvalidator = @"
            function IssueDescValidation(sender, args) {
                var issuedesc = document.getElementById(sender.controltovalidate);
                if (issuedesc.innerText.length > 0) { args.IsValid; };
            }";

    return issuedescvalidator;
}

The above validation code resides within a custom validator class, which also contains validation code for dropdown list controls which I have on the same content page as this multi-line textbox.

For some reason, my Javascript validator for the multiline textbox is not firing when the textbox contains no text. The problem is that's exactly the condition I'm trying to validate for. When I type in some random text and then try to submit the form, the validator fires.

The dropdown lists are validating perfectly. I think that I'm not using the correct property to find the length of the textbox, but I'm not really sure what's going wrong at this point. Any ideas?

+1  A: 

You need to set the ValidateEmptyText property on your validator to True.

patmortech