c# - MasterPage 中的 ValidationSummary 隐藏成功标签

标签 c# asp.net master-pages validationsummary

我在 MasterPage
中有一个 ValidationSummarySuccessLabelSuccessLabel 中有详细信息,然后 ValidationSummary 验证失败时,我希望它隐藏 SuccessLabel 并只显示 验证摘要

<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/

相关文章:

c# - 将百分比文本添加到进度条 C#

C# 反序列化 JSON 以在 foreach 循环中使用

javascript - 将服务器控件的值传递给 ASPx 客户端事件

asp.net - 基本页或基本母版页或嵌套母版页?

c# - 网站上的母版页,但在 asp.net 的源代码中没有母版页?

c# - 将 ICommand 绑定(bind)到按钮?

c# - 根据大小对数字范围进行分区,然后找到该范围内给定数字的分区起点

c# - 检测 UpdatePanel 是否受到 Update() 方法调用的影响

javascript - 调用javascript函数时出错: ReferenceError: <function name> is not defined

c# - 如何处理内容页中的母版页按钮事件?