2

我有一个ValidationSummaryandSuccessLabelMasterPage
其中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 函数。

谢谢,亚历克斯

4

2 回答 2

0

您的验证码完全错过了很多字段。

好的,现在我们去你的品脱。

  1. 在页面加载事件的标签中设置可见 false
  2. 然后成功时间添加标签文本,并设置可见真
  3. 您错过了验证和验证组以及显示字段的控制权

请看这个样本

于 2013-03-08T12:02:29.767 回答
0

像这样的东西怎么样:

    protected void Submit(object sender, EventArgs e)
    {
        if (IsValid)
        {
            StatusLabel.Visible = true;
        }
        else
        {
            StatusLabel.Visible = false;                
        }
    }
于 2013-03-08T11:52:11.510 回答