Now: Tutorial for Web and Software Design > Web Design > ASP > Web Design Content
> Taming the ASP.NET Validation Summary Control [Bookmark it]
Taming the ASP.NET Validation Summary Control

Taming the ASP.NET Validation Summary Control

by Manu Gupta

ASP.NET provides a lot of very strong and effective web controls. One of the most widely used controls is the Validation Summary control. It gives us a neat and clean way to display error messages on the web page.

During my current program assignment I came across a problem when I had to disable the Validation Summary control on one button click and enable Validation Summary control on the same or other button click.

I know some of you might say OH what a big deal just use enable or visible property and we can accomplish the task. Yes you can but if you are not getting the desired result that you wanted, please read further.

One of the basic problems, I came across was disabling the page validation summary control while displaying customized error messages. I was running into an issue where duplicate error messages were being displayed on the screen. After finally finding a solution to the problem, I would like to share my solution with you hard working programmers so that maybe this solution will save you some pain of taming Validation Summary control of ASP.NET.

The following also deals with a problem of going back functionality on secure pages with https. If you are getting the Warning page expired message when you click back button to go to previous screen, the use of following article can come handy.

This example requires just very basic knowledge of java script so don't be scared. I promise this will be one of the easiest java scripts and it can solve a complex problem.

Add the following text to the page tag on top of your aspx page:

clienttarget="downlevel"

The modified page tag will look something like this:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Mypage.aspx.vb" Inherits="MyPage" clienttarget="downlevel" %>

Then add the following java script to your page:

<script language="JavaScript">

document.all["buttonName"].onclick = new function("Page_ValidationActive=true;");

</script>

Then add the following code to the button click event:


Page.Validate()



If Page.IsValid Then

	Lblerror.text = "your custom error message"

	If Validationsummary1.Visible = True Then

		Validationsummary1.Visible = False

	End If

Else

	If Validationsummary1.Visible = False Then

		Validationsummary1.Visible = True

		lblError.Text = ""

	End If

End If

Where ValidationSummary1 is the validation summary control on the page and lblError is the label control to display your custom error messages.

In addition to this, if you want to disable the page validation on the cancel event of some secured page [to go back to previous page] that is a page with https, you might want add the following java script to your aspx page

<script language="JavaScript">

document.all["CancelbuttonName"].onclick = new function("Page_ValidationActive=false;");

</script>

GOOD LUCK !!!

Manu Gupta
Senior Programmer Analyst
Progressive Consulting Technologies

[Bookmark][Print] [Close][To Top]
  • Prev Article-Web Design:

  • Next Article-Web Design:
  • Related Materias
    Microsoft Expression Web D
    Storing Data from Dynamic 
    Multi-User Login With Data
    Effective Data Paging Usin
    Microsoft Announces Visual
    How to Protect Your Applic
    How To Change Network Inte
    Update Multiple Records wi
    ASP.NET 2.0 Compilation Mo
    Important Information Abou
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial