0

I have a custom control included in a form that includes a dropdown list. The form has a number of other required fields, so i was wondering how to validate this dropdown.

<gaia:TextBox ID="TitleTextBox" runat="server"/>
<gaia:RequiredFieldValidator runat="server" ControlToValidate="TitleTextBox"
                    ErrorMessage="Please fill in the press release title" Text="*" Display="None" ValidationGroup="save" />

<CN:ProductCategoryDropDown runat="server" ID="ProductCategoryDropDown" />
<gaia:CustomValidator runat="server" ID="ProductCategoryValidator" OnServerValidate="ProductCategory_Validate" ValidationGroup="save" 
                    Display="None" Text="*" ErrorMessage="Please select a category"  />

the code behind looks like this

protected void ProductCategory_Validate(object source, ServerValidateEventArgs args)
{
    args.IsValid = (ProductCategoryDropDown.SelectedValue>0);
}

On the customvalidator above, I purposely left out the 'ControlToValidate' because it throws an error.

Please help.

4

1 回答 1

0

最简单的方法是CustomValidatorUserControl.

然后,您可以为 Validation-Group 和另一个属性提供一个属性ValidatorEnabled来设置验证器组并启用/禁用验证器。

于 2012-05-23T10:49:52.673 回答