DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > Code Samples > .Net

Discuss "Programmatically Add Item to Validation Summary" in the .Net forum.

.Net - Post your ASP.net and Windows Forms code samples here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old March 20th, 2008, 09:41 AM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 537
Thanks: 14
Thanked 40 Times in 39 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft Windows Microsoft .Net Microsoft SQL Server Classic ASP 
Total Awards: 4

Default Programmatically Add Item to Validation Summary

I had an instance where I wanted to simply set off ASP.Net's ValidationSummary control to display an error to the user instead of creating another element to handle this. After some research, I came across the IValidator class.
Code:
Imports System.Web.UI
    Public Class ValidationError
        Implements IValidator
        Private _errorMessage As String = String.Empty
        Private _isValid As Boolean = False
        Public Shared Sub Display(ByVal message As String)
            Dim currentPage As Page = TryCast(HttpContext.Current.Handler, Page)
            currentPage.Validators.Add(New ValidationError(message))
        End Sub
        Public Sub New(ByVal message As String)
            ErrorMessage = message
            IsValid = False
        End Sub
        Public Property ErrorMessage() As String Implements System.Web.UI.IValidator.ErrorMessage
            Get
                Return _errorMessage
            End Get
            Set(ByVal value As String)
                _errorMessage = value
            End Set
        End Property
        Public Property IsValid() As Boolean Implements System.Web.UI.IValidator.IsValid
            Get
                Return _isValid
            End Get
            Set(ByVal value As Boolean)
                _isValid = value
            End Set
        End Property
        Public Sub Validate() Implements System.Web.UI.IValidator.Validate
        End Sub
    End Class
To call this, simply do the following:
Code:
Page.Validate()
ValidationError.Display("Place error message here")
__________________
jmurrayhead
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
Reply With Quote
Sponsored Links
Reply

  DeveloperBarn Forums > Programming & Scripting > Code Samples > .Net

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 09:37 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46