簡體   English   中英

MasterPage中的ValidationSummary隱藏成功標簽

[英]ValidationSummary in MasterPage hide success label

我在MasterPage有一個ValidationSummarySuccessLabel
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;                
        }
    }

您的驗證碼完全錯過了很多字段。

好的現在我們要努力了。

  1. 為頁面加載事件在標簽中設置visible false
  2. 然后成功時間添加標簽文本,並設置visible true
  3. 您錯過了進行驗證和驗證的控件組和顯示字段

請看這個樣品

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM