【问题标题】:how to validate checkboxlist that will generate from the database values如何验证将从数据库值生成的复选框列表
【发布时间】:2013-11-22 14:32:15
【问题描述】:

在asp.net,C#中没有checkboxlist的验证控件。 复选框将从数据库值生成,并将放置在面板中。 但问题是我无法验证复选框列表。 谁能告诉我,我该如何解决这个问题。

【问题讨论】:

  • 您必须使用带有 clientID 信息的 jquery

标签: c# asp.net validation checkboxlist


【解决方案1】:

在代码中使用CustomValidator 以使用 ASP.NET 进行验证。

<asp:CheckBoxList ID="CheckBoxList1" runat="server"
    ClientID="MyCBL"
    DataSource="datasource"
    DataTextField="display"
    DataValueField="value">
</asp:CheckBoxList>

<asp:CustomValidator ID="CustomValidator1" runat="server"
    ErrorMessage="You must select a value."
    ClientValidationFunction="VerifyCheckBoxList">
</asp:CustomValidator>

Javascript

function VerifyCheckBoxList(sender, args) {
    var mycbl = document.getElementById('<%=MyCBL.ClientID%>').value;
    if (...) { // verify your checkbox list here
        args.IsValid = false; // pass false to cancel postback
    }
    else {
        // do your other things
    }
}

看看http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator(v=vs.110).aspx的MSDN页面

【讨论】:

    猜你喜欢
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    相关资源
    最近更新 更多