SunQuest
 
           Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 2nd, 2008, 05:10 PM
jmurrayhead's Avatar
jmurrayhead jmurrayhead is offline
The Drunken Moderator
ASP Free God 17th Plane (13000 - 13499 posts)
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 13,028 jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 78618 Folding Title: Intermediate FolderFolding Points: 78618 Folding Title: Intermediate FolderFolding Points: 78618 Folding Title: Intermediate FolderFolding Points: 78618 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 5 Days 8 h 15 m 58 sec
Reputation Power: 1535
Facebook
ASP.Net/VB.Net - Programmatically Add Item to ValidationSummary

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.

VB.Net Code:
Original - VB.Net Code
  1. Imports System.Web.UI
  2.  
  3.     Public Class ValidationError
  4.         Implements IValidator
  5.  
  6.         Private _errorMessage As String = String.Empty
  7.         Private _isValid As Boolean = False
  8.  
  9.         Public Shared Sub Display(ByVal message As String)
  10.             Dim currentPage As Page = TryCast(HttpContext.Current.Handler, Page)
  11.             currentPage.Validators.Add(New ValidationError(message))
  12.         End Sub
  13.  
  14.         Public Sub New(ByVal message As String)
  15.             ErrorMessage = message
  16.             IsValid = False
  17.         End Sub
  18.  
  19.         Public Property ErrorMessage() As String Implements System.Web.UI.IValidator.ErrorMessage
  20.             Get
  21.                 Return _errorMessage
  22.             End Get
  23.             Set(ByVal value As String)
  24.                 _errorMessage = value
  25.             End Set
  26.         End Property
  27.  
  28.         Public Property IsValid() As Boolean Implements System.Web.UI.IValidator.IsValid
  29.             Get
  30.                 Return _isValid
  31.             End Get
  32.             Set(ByVal value As Boolean)
  33.                 _isValid = value
  34.             End Set
  35.         End Property
  36.  
  37.         Public Sub Validate() Implements System.Web.UI.IValidator.Validate
  38.  
  39.         End Sub
  40.     End Class


To call this, simply do the following:
VB.Net Code:
Original - VB.Net Code
  1. Page.Validate()
  2. ValidationError.Display("Place error message here")
__________________
jmurrayhead

Did I help you out? Make me popular by clicking the icon!

New Members:Proper way to post a question

Powered by ASP.Net

Reply With Quote
  #2  
Old March 4th, 2008, 11:25 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 325325 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325325 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325325 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325325 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325325 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325325 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 12 h 53 m 47 sec
Reputation Power: 1400
nice, thanks for sharing!

Reply With Quote
  #3  
Old March 4th, 2008, 11:29 AM
jmurrayhead's Avatar
jmurrayhead jmurrayhead is offline
The Drunken Moderator
ASP Free God 17th Plane (13000 - 13499 posts)
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 13,028 jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 78618 Folding Title: Intermediate FolderFolding Points: 78618 Folding Title: Intermediate FolderFolding Points: 78618 Folding Title: Intermediate FolderFolding Points: 78618 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 5 Days 8 h 15 m 58 sec
Reputation Power: 1535
Facebook
Quote:
Originally Posted by Shadow Wizard
nice, thanks for sharing!


Indeed, it's been coming in very handy for me. I hope it will be useful to others

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > ASP.Net/VB.Net - Programmatically Add Item to ValidationSummary


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway