2013-03-08 19 views
2

我在MasterPage
得到了ValidationSummarySuccessLabelSuccessLabel有詳細的它,然後ValidationSummary然後驗證失敗我希望它隱藏SuccessLabel,並只顯示ValidationSummary的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函數。

謝謝, 亞歷克斯

回答

0

怎麼是這樣的:

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

您的驗證碼是完全錯過很多領域。

好吧,現在我們正在你的品脫。

  1. 設置上可見的僞在標籤頁面加載事件
  2. 那麼成功時添加標籤的文本,並設置明顯的真
  3. 你錯過了控制,驗證和的ValidationGroup和顯示領域

請看這sample