Validation Summary additions

Posted on 2007-10-20
Last Modified: 2010-07-27
I want to put my validation summary around some HTMl that i have built for the validation summary.

How do i customize the smmary to show inside this HTML, or more importantly to hide and show to html containing it...

<table> <----- Want to hide and show this table with the validation summary.
<asp:ValidationSummary ID="ErrSummary" HeaderText="The following errors occured:"
ShowSummary="true" DisplayMode="BulletList" runat="server" />

Any help would be great,
Question by:Nugs
    LVL 8

    Expert Comment

    Whenever I ask the Visual Desiger at work about these requests he usually uses custom rolled JavaScript to hide elements like tables, or he places controls inside of a <DIV> and sets the visibility there.
    LVL 10

    Expert Comment

    you can set CssClass and set Display=None to hide the entire validation summary

    or you can modifie your ErrorMessage like

    ErrorMessage="<B>" + ErrorMessage
    then add above ErrorMessage in you customValidator control

    LVL 5

    Accepted Solution

    Suppose you have a form with some input fields, validators and a submit button:

            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />

    and then you have your validation summary, enclosed in some table:

                    <td><asp:ValidationSummary ID="ValidationSummary1" runat="server" /></td>

    1) Make the table run on the server & set it's style to display:none, like this:
    <table runat="server" ID="ValSumTable" style="display:none">

    We're doing this so a) we have an id for the table and b) we can reference it from the server-side code

    2) Add this code to your Page_Load:

                      "document.getElementById('" + ValSumTable.ClientID + "').style.display = Page_IsValid ? 'none' : '';");

    This adds a small script to run after the validation but before the submit. It will show/hide the table, together with the validation summary.

    3) Add this to the Button1_OnClick (submit) event:

                ValSumTable.Style["display"] = Page.IsValid ? "none" : "";

    This is necessary in case the client-script validation is disabled.
    LVL 2

    Author Comment

    Awesome, thank you very much...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now