Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3484476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:47:34+00:00 2026-05-18T10:47:34+00:00

I have the following markup. The errorPanel was first only used to show server

  • 0

I have the following markup. The errorPanel was first only used to show server side exception messages, and works fine like that. Now I’d like to incorporate my validation summary into that same errorPanel.

<asp:Panel ID="errorPanel" runat="server" CssClass="error" Visible="false">
    <div style="float: right;">
        <a href="#" class="error-close" style="font-size: 10px">Close</a></div>
    <asp:Label ID="errorLabel" runat="server"></asp:Label>
    <asp:ValidationSummary ID="validationSummary" runat="server" EnableClientScript="true" />
</asp:Panel>
<fieldset>
    <legend>Create New Role</legend><asp:Label ID="newRoleNameLabel" runat="server" AssociatedControlID="newRoleNameText">Role Name:</asp:Label>
    <asp:TextBox ID="newRoleNameText" runat="server" Width="100px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="newRoleNameRequired" runat="server" EnableClientScript="true" ControlToValidate="newRoleNameText" Display="Dynamic" ErrorMessage="Please enter a role name.">*</asp:RequiredFieldValidator>
    <asp:Button ID="createButton" runat="server" Text="Create" OnClick="createButton_Click" />
</fieldset>

My problem now is that the required validation happens client side, and I want to keep that, so I have no server side opportunity to make errorPanel visible, in order to make the validation summary visible.

I see I have two options: Do validation server side, and use my code there to make the panel visible, or hook into the client side code somehow and catch an event there when the summary should be made visible, and then also make the errorPanel visible. How could I go about the latter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:47:34+00:00Added an answer on May 18, 2026 at 10:47 am

    Here is an approach which is really not recommended, but I had fun writing it, and it might lead you to some zany ideas!

    (p.s. I am using jQuery to make life easier)

    Take the Visible="false" off your asp:Panel, we’ll do it all client side.

    <asp:Panel ID="errorPanel" runat="server" CssClass="error">
    

    Now, at document ready time we will hide the panel, and mess with ASP.NET’s validation code.

    $(document).ready(function () {
        // This is more like it!
        $("#<% =errorPanel.ClientID %>").hide();
        eval('ValidatorCommonOnSubmit = ' + ValidatorCommonOnSubmit.toString().replace('return result;', 'myValidatorHook(result); return result;'));
    });
    

    That eval takes the ValidatorCommonOnSubmit() function which is generated by the ASP.NET validators, and modifies it in place so just before it returns its result, it calls myValidatorHook() with that result.

    (see this StackOverflow question for where I got the idea)

    Now, our hook:

    function myValidatorHook(validated) {
        if (validated) {
            $("#<% =errorPanel.ClientID %>").hide();
        }
        else {
            $("#<% =errorPanel.ClientID %>").show();
        }
    }
    

    Simple enough – if the validator returned true (page validates), hide the panel; if it returned false (page did not validate), show it.

    Use at your own risk! If the JavaScript generated by the ASP.NET validators changes, this will break horribly – but I did test it in ASP.NET 2.0, 3.5 and 4.0, and it worked the same in all three.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following markup that is used to produce a pop-up style mega-menu
I have the following markup: <tr> <td valign=top align=left> <asp:Label ID=Label1 runat=server Text=Available Roles
I have the following markup with inline javascript and would like to change it
I have the following markup, and I want to make the All radio button
I have the following markup for buttons (can be changed, but I really don't
I have the following markup, I took the extra stuff out of the divs,
I have the following markup: <div class="header">Text</div> <div class="hiddenArea">sdsada</div> <div class="header">Text2</div> <div class="hiddenArea">sdsada</div> and
I have the following markup, <ul id=menu> <li><a href=#>Something1</a></li> <li><a href=#>Something2</a></li> <li><a href=#>Something3</a></li> <li><a
I have the following markup: <div id=routes> <ul id=routesList> <li class=routes>Route 1</li> <li class=routes>Route
I have the following markup <div class=question> <h2>Title 1</h2> <div class=answer>content 1</div> </div> <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.