gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:35 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com