Go Back   DeveloperBarn Forums > Programming & Scripting > Code Samples

Sponsored Links

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

Code Samples - Search through our code samples to give your application that something extra or provide a code sample of your own.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old March 20th, 2008, 09:41 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net 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
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
Sponsored Links
Reply

  DeveloperBarn Forums > Programming & Scripting > Code Samples

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
validation todd2006 JavaScript Programming 5 July 30th, 2008 09:23 AM
How do you add a static item to a dynamic dropdownlist Shem .Net Development 19 July 4th, 2008 08:14 AM
textbox validation todd2006 JavaScript Programming 6 July 2nd, 2008 01:30 PM
[ASP.Net/VB.Net] Programmatically Select Item in ListBox or DropDownList jmurrayhead Code Samples 0 June 27th, 2008 10:05 AM
Loop / Summary help Rebelle ASP Development 7 April 11th, 2008 10:12 AM


All times are GMT -4. The time now is 07:26 PM.



Content Relevant URLs by vBSEO 3.2.0