【发布时间】:2017-02-04 12:12:51
【问题描述】:
如何验证 asp.net 中的 html 复选框?
我试过以下。
<input type="checkbox" id="chk_rule" class="checkbox-custom" name="chk_rule" runat="server"/>
<label for="bodycontent_chk_rule" class="checkbox-custom-label">I have read and agree to the official rules</label>
<asp:CustomValidator ID="Agreecheck" runat="server" Display="Dynamic" ForeColor="Red" ErrorMessage="You have to agree the rules." ControlToValidate="chk_rule" OnServerValidate="Agreecheck_ServerValidate"></asp:CustomValidator>
服务器端验证功能如下。
protected void Agreecheck_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = chk_rule.Checked;
}
但是我遇到了以下错误。
消息:无法找到由 'Agreecheck' 的 'ControlToValidate' 属性。堆栈跟踪:在 System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(字符串 名称,字符串属性名称)在 System.Web.UI.WebControls.CustomValidator.ControlPropertiesValid() 在 System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint)
我该如何解决这个问题?
【问题讨论】:
-
您使用母版页吗?
-
请查看link
-
@FarzInKanz 我使用母版页。
标签: asp.net validation