开发者

Easily Validate a CheckBoxList

Am trying to elegantly validate a CheckBo开发者_如何学GoxList in ASP.NET webforms.

Problem: Unknown server tag 'cc:ValidateableCheckBoxList'.

namespace fmwebapp1.UserControls
{
    [ValidationPropertyAttribute("ValidateableProperty")]
    public class ValidateableCheckBoxList : CheckBoxList
    {
        public string ValidateableProperty
        {
            get { return (this.Items.Cast<ListItem>().Where(i => i.Selected).Count() > 0) ? "something was selected" : ""; }
        }
    }
}

In the same namespace as my aspx file:

 <%@ Register Namespace="fmwebapp1.UserControls" Assembly="ValidateableCheckBoxList" TagPrefix="cc" %>   
<cc:ValidateableCheckBoxList runat="server" ID="cblFindTheSite">
                                        <asp:ListItem>The Press</asp:ListItem>
                                        <asp:ListItem>blah1</asp:ListItem>
                                        <asp:ListItem>blah2</asp:ListItem>
                                                                                </asp:CheckBoxList>
                                    <div class="validators">
                                        <asp:RequiredFieldValidator runat="server" ID="rfvTest" ControlToValidate="cblFindTheSite" Text="Failed validation" ></asp:RequiredFieldValidator>
                                    </div>


Check that the assembly referenced in the Web Application matches the "Assembly" attribute in your Register directive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜