我的CustomValidator无效。它没有显示ErrorMessage

时间:2015-02-05 10:25:12

标签: asp.net

我的CustomValidator未显示ErrorMessage。它是“IsExistingCompanyName”并返回false但CustomValidator未显示ErrorMessage =“公司名称已注册”。请记住,我只有一个ValidationGroup =“商业形式”,我用于所有控件,如电子邮件地址,手机号码。等

HTML:

<td width="495">
    <telerik:RadTextBox 
        ID="uxCompanyName" 
        runat="server" 
        MaxLength="100" 
        ValidationGroup="commercial-form">
    </telerik:RadTextBox>
    <span class="validator-show">
    <asp:RequiredFieldValidator 
        ID="rfvuxCompanyName" 
        runat="server" 
        ErrorMessage="*" 
        ValidationGroup="commercial-form"
        Display="Dynamic"
        ControlToValidate="uxCompanyName">
    </asp:RequiredFieldValidator>
    </span>
    <span class="validator-show">
    <asp:CustomValidator 
        runat="server" 
        ID="cvuxCompanyName" 
        OnServerValidate="IsExistingCompanyName" 
        ValidationGroup="commercial-form" 
        ControlToValidate="uxCompanyName" 
        ErrorMessage="Company name is already registered" 
        Display="Dynamic"
        ValidateEmptyText="True">
    </asp:CustomValidator>
    </span>
</td>

代码:

protected void IsExistingCompanyName(object sender, ServerValidateEventArgs e)
{
    if (this.userInformation.IsExistingCompanyName(0, this.uxCompanyName.Text.Trim()))
    {
        e.IsValid = false;
        uxCompanyName.Focus();
    }
    else
    {
        e.IsValid = true;
    }
}

在页面加载:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.Page.IsPostBack)
    {
        this.rfvuxCompanyName.Enabled = true;
        this.cvuxCompanyName.Enabled = true;

        this.revuxEmail.Enabled = true;
        this.revuxEmail.Enabled = true;
    }
}

保存:

public bool Save()
{
    lblSaveStatus.Visible = false;
    this.Page.Validate("commercial-form");
    if (!this.Page.IsValid)
    {
        return false;
    }
}

请为此提供帮助。感谢

0 个答案:

没有答案