【问题标题】:ASP.NET Forms CustomCustomvalidator - always correct valueASP.NET Forms Custom Customvalidator - 总是正确的值
【发布时间】:2014-09-18 09:42:50
【问题描述】:

我在 ASP.NET Forms 中创建了简单的页面,我需要使用 CustomValidator 控件。代码如下:

Page.aspx

<asp:ListBox 
    ID="listControl" runat="server" 
    ClientIDMode="Static" 
    onchange="toggleButton(this, document.getElementById('remove'))" />


<asp:CustomValidator 
    ID="fmValidator" 
    ControlToValidate="listControl"
    CssClass="IncorrectResult" 
    runat="server" 
    ValidateEmptyText="True" 
    ErrorMessage="..." 
    Text="..." 
    OnServerValidate="Validator_OnServerValidate" />

Page.aspx.cs

protected void Validator_OnServerValidate(object source, ServerValidateEventArgs  args)
{
    if(isAdmin)
    {
        args.IsValid = true;
    }
    else
    {
        args.IsValid = false;
    }
}

关键是我可以使用正确的数据在Validator_OnServerValidate 中捕获一个事件,但是无论我在args.IsValid 中输入什么(我的意思是对或错),它总是返回正确的值 - 在网页上一切都是正确的。怎么了?

【问题讨论】:

    标签: asp.net validation webforms


    【解决方案1】:

    那是因为页面在验证时没有重新加载。我所要做的就是启用客户端验证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多