我在ValidationSummary中有一个SuccessLabelMasterPage
SuccessLabel中有详细信息时,然后ValidationSummary然后验证失败,我希望它隐藏SuccessLabel而仅显示ValidationSummary

<div id="ApplicationStatus" class="ValidationSummaryContainer">
    <asp:Label ID="StatusLabel" CssClass="SuccessSummary" runat="server"
       Visible="false"></asp:Label>
    <asp:Label ID="WarningLabel" CssClass="WarningSummary" runat="server"
        Visible="false"></asp:Label>
    <asp:ValidationSummary ID="ErrorValidationSummary" runat="server"
           CssClass="ValidationSummary" DisplayMode="List"  />
    <asp:CustomValidator ID="ErrorCustomValidator" runat="server"></asp:CustomValidator>
</div>
<div id="ApplicationContent" class="ApplicationContentContainer">
    <asp:ContentPlaceHolder ID="MainContent" runat="server">
    </asp:ContentPlaceHolder>
</div>

protected void Page_Load(object sender, EventArgs e)
{
        if (!IsPostBack)
        {
            StatusLabel.Text = "Successfully loaded record";
        }
}


<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
       <asp:Textbox ID = "Text1" runat="server"/>
        <asp:RequiredFieldValidator id="InputTextBoxRequiredFieldValidator" runat="server"
          ControlToValidate="Text1" Visible="false" CssClass="InlineNoWrap" Enabled="true">
        </asp:RequiredFieldValidator>
        <asp:Button ID = "Button1" runat="server" Text="Submit"/>
 </asp:Content>


我试图在JavaScript中找到一种方法来捕获验证错误并隐藏StatusLabel。
我不想在使用MasterPage的每个页面上的每个按钮上都放置一个javascript函数。

谢谢,
亚历克斯

最佳答案

这样的事情怎么样:

    protected void Submit(object sender, EventArgs e)
    {
        if (IsValid)
        {
            StatusLabel.Visible = true;
        }
        else
        {
            StatusLabel.Visible = false;
        }
    }

关于c# - MasterPage中的ValidationSummary隐藏成功标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15293072/

10-12 15:59