C# 验证页面中自定义控件的下拉列表
我有一个自定义控件包含在一个包含下拉列表的表单中。表单还有许多其他必填字段,所以我想知道如何验证这个下拉列表C# 验证页面中自定义控件的下拉列表,c#,asp.net,C#,Asp.net,我有一个自定义控件包含在一个包含下拉列表的表单中。表单还有许多其他必填字段,所以我想知道如何验证这个下拉列表 <gaia:TextBox ID="TitleTextBox" runat="server"/> <gaia:RequiredFieldValidator runat="server" ControlToValidate="TitleTextBox" ErrorMessage="Please fill in the press r
<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" />
在上面的customvalidator上,我故意省略了“ControlToValidate”,因为它抛出了一个错误
请提供帮助。最简单的方法是在
UserControl
中包含CustomValidator
然后,您可以为验证组提供一个属性,并提供另一个
ValidatorEnabled
来设置验证程序组并启用/禁用验证程序 我忘了检查页面是否有效。SOLVEDPut if(!Page.IsValid){return;}在提交代码中..尝试另一篇文章:[希望这能对您有所帮助![1]:
protected void ProductCategory_Validate(object source, ServerValidateEventArgs args)
{
args.IsValid = (ProductCategoryDropDown.SelectedValue>0);
}