2

I've got a ValidationSummary and SuccessLabel in the MasterPage
When the SuccessLabel has detail in it, and then the ValidationSummary then fails validation I want it to hide the SuccessLabel and only show the 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>

I'm trying to find a way in JavaScript to catch the validation error and hide the StatusLabel. I don't want to have to put a javascript function on every button on every page that uses the MasterPage.

Thanks, Alex

शेखर
  • 17,412
  • 13
  • 61
  • 117
Alex Driver
  • 73
  • 1
  • 5

2 Answers2

0

How about something like this:

    protected void Submit(object sender, EventArgs e)
    {
        if (IsValid)
        {
            StatusLabel.Visible = true;
        }
        else
        {
            StatusLabel.Visible = false;                
        }
    }
शेखर
  • 17,412
  • 13
  • 61
  • 117
andreasnico
  • 1,478
  • 14
  • 23
0

Your validation code are totally miss lot of fields.

ok now we are going your pint .

  1. Set visible false in your label for page load event
  2. then success time add the label text ,and set visible true
  3. you miss control to validate and validationgroup and display fields

please see this sample

शेखर
  • 17,412
  • 13
  • 61
  • 117