Custom Field RequiredFieldValidator Highlighting

There was a great post here by Yoann. B that provided a great example in C# for highlighting RequireFieldValidators: http://blog.sb2.fr/post/2008/12/12/Custom-TextBox-Required-Field-Validator.aspx

I expanded the code to allow for border widths, and converted the code to VB.

[codesyntax lang=”vbnet”]

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Text

Namespace Validators
	<DefaultProperty("Text")> _
	 <ToolboxData("<{0}:TextBoxRequiredFieldValidator runat=server></{0}:TextBoxRequiredFieldValidator>")> _
	 Public Class TextBoxRequiredFieldValidator
		Inherits RequiredFieldValidator
#Region "Public Properties"

		Public Property ErrorBackgroundColor() As Color
			Get
				If ViewState("ErrorBackgroundColor") Is Nothing Then
					Return Color.LightGray
				Else
					Return DirectCast(ViewState("ErrorBackgroundColor"), Color)
				End If
			End Get
			Set(ByVal value As Color)
				ViewState("ErrorBackgroundColor") = value
			End Set
		End Property
		Public Property ErrorBorderColor() As Color
			Get
				If ViewState("ErrorBorderColor") Is Nothing Then
					Return Color.Red
				Else
					Return DirectCast(ViewState("ErrorBorderColor"), Color)
				End If
			End Get
			Set(ByVal value As Color)
				ViewState("ErrorBorderColor") = value
			End Set
		End Property
		Public Property ErrorBorderWidth() As Unit
			Get
				If ViewState("ErrorBorderWidth") Is Nothing Then
					Return Unit.Pixel(1)
				Else
					Return DirectCast(ViewState("ErrorBorderWidth"), Unit)
				End If
			End Get
			Set(ByVal value As Unit)
				ViewState("ErrorBorderWidth") = value
			End Set
		End Property

#End Region

#Region "Private Properties"

		Private Property OriginalBackgroundColor() As Color
			Get
				If ViewState("OriginalBackgroundColor") Is Nothing Then
					Return Color.LightGray
				Else
					Return DirectCast(ViewState("OriginalBackgroundColor"), Color)
				End If
			End Get
			Set(ByVal value As Color)
				ViewState("OriginalBackgroundColor") = value
			End Set
		End Property
		Private Property OriginalBorderColor() As Color
			Get
				If ViewState("OriginalBorderColor") Is Nothing Then
					Return Color.Red
				Else
					Return DirectCast(ViewState("OriginalBorderColor"), Color)
				End If
			End Get
			Set(ByVal value As Color)
				ViewState("OriginalBorderColor") = value
			End Set
		End Property
		Private Property TextBoxToValidate() As TextBox
			Get
				Return m_TextBoxToValidate
			End Get
			Set(ByVal value As TextBox)
				m_TextBoxToValidate = value
			End Set
		End Property
		Private m_TextBoxToValidate As TextBox

#End Region

#Region "Protected Overrides Methods"

		Protected Overrides Sub OnInit(ByVal e As EventArgs)
			MyBase.OnInit(e)

			Dim txt As TextBox = TryCast(Me.FindControl(MyBase.ControlToValidate), TextBox)
			If txt IsNot Nothing Then
				TextBoxToValidate = txt

				OriginalBackgroundColor = TextBoxToValidate.BackColor
				OriginalBorderColor = TextBoxToValidate.BorderColor
			End If
		End Sub
		Protected Overrides Function EvaluateIsValid() As Boolean
			Dim bIsValid As [Boolean] = False
			Dim Value As [String] = MyBase.GetControlValidationValue(MyBase.ControlToValidate)
			If [String].IsNullOrEmpty(Value) Then
				If TextBoxToValidate IsNot Nothing Then
					TextBoxToValidate.BackColor = ErrorBackgroundColor
					TextBoxToValidate.BorderColor = ErrorBorderColor
					bIsValid = False
				End If
			Else
				If TextBoxToValidate IsNot Nothing Then
					TextBoxToValidate.BackColor = OriginalBackgroundColor
					TextBoxToValidate.BorderColor = OriginalBorderColor
					bIsValid = True
				End If
			End If
			Return bIsValid
		End Function
		Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
			MyBase.OnPreRender(e)

			If Page.ClientScript.IsClientScriptBlockRegistered("ValidationScript") Then
				Return
			End If

			Dim ControlToValidateClientId As [String] = MyBase.GetControlRenderID(MyBase.ControlToValidate)

			Dim Script As New StringBuilder()
			Script.Append("<script language=""javascript"">")

			Script.Append("function RequiredFieldValidatorEvaluateIsValid(val) {")
			Script.Append("    var value = ValidatorGetValue(val.controltovalidate);")
			Script.Append("if (value == '') {")

			Script.Append("document.getElementById(val.controltovalidate).style.backgroundColor = '$$BGCOLOR$$';")
			Script.Replace("$$BGCOLOR$$", ColorTranslator.ToHtml(ErrorBackgroundColor))

			Script.Append("document.getElementById(val.controltovalidate).style.borderColor = '$$BRCOLOR$$';")
			Script.Replace("$$BRCOLOR$$", ColorTranslator.ToHtml(ErrorBorderColor))

			Script.Append("document.getElementById(val.controltovalidate).style.borderWidth = '$$BRWIDTH$$';")
			Script.Replace("$$BRWIDTH$$", ErrorBorderWidth.ToString)

			Script.Append("return false;    }")
			Script.Append("else {")

			Script.Append("document.getElementById(val.controltovalidate).style.backgroundColor = '$$ORIG_BGCOLOR$$';")
			Script.Replace("$$ORIG_BGCOLOR$$", ColorTranslator.ToHtml(OriginalBackgroundColor))

			Script.Append("document.getElementById(val.controltovalidate).style.borderColor = '$$ORIG_BRCOLOR$$';")
			Script.Replace("$$ORIG_BRCOLOR$$", ColorTranslator.ToHtml(OriginalBorderColor))

			Script.Append("return true;} }")
			Script.Append("</script>")

			Page.ClientScript.RegisterClientScriptBlock(Me.[GetType](), "ValidationScript", Script.ToString())
		End Sub

#End Region
	End Class
End Namespace

[/codesyntax]

Here is the usage of the Overload.

You must register the custom control on the page, include the “Assembly” attribute if from outside your project.

[codesyntax lang=”vbnet”]

<%@ Register TagPrefix="MyCtrl" Namespace="Validators" %>

[/codesyntax]

The control is used just like the regular required field validator.

[codesyntax lang=”vbnet”]

<myctrl:textboxrequiredfieldvalidator ID="valid1" runat="server" ControlToValidate="TextBox1" ErrorBackgroundColor="Red" ErrorBorderColor="Red" ErrorBorderWidth="2" SetFocusOnError="true"></myctrl:textboxrequiredfieldvalidator>

[/codesyntax]

Quick notes on SEO WebCast

Alex Gould – High Search Engine Rankings

2/24/2011-New Panda Google Release “We lanched a pretty big algorithmic change 12%”

1. Be the athority in your niche field. (Start Social Network Niche, be involved in groups)

2.When writing comment on the big names in your field, built rapar with them.

a.Add quality comments to pages and include Links

3.Wikipedia Links are very valuable, try to get them.

4.Bookmarking sites like Delicious, Faves.com, furl.com, Stumbleupon.com

a. Bookmark ever article and page on your website, also bookmark pages that link to your site.

5.Social Poster (Tool)
5.Local Directories

a.Classified Ads, usfreeads,craigslist,epage

b.Universitys, Chamber of Commerece, niche directories

5.Yahoo site explorer

5.SEO Link Vine

5.Statbrain, websiteoutlook, builtwith, snapshot, quantcast, cubestat,siteadvisor, robtex.com, zimbio, searchanalytics.complete.com

6.Videos

a.Create videos with targeted keywords

b.Tag videos with links to website, and call to action to visit website

c.Tubemogal, Animoto, cantatia (Video tools)

7.Digg, Redit, DZone

a.di66.net (Youtube Content Source) Digg your youtube videos (most diggs are videos)

8.Reviews

a.ePenions, osoyou.com, q&a sites (yahoo answers, eHow comments)

b.Try switching proxy to add comments from different IP

9.Content Sharing

a.Squidoo, Hubpage

10.Artical Submission

a.ishare, ezine articles, go articles, syndicate your articals, convert articles to pdf/slide shows and submit, spin content 50%.

11.Track what you do

a.Use excel file to track all links, comments posted, RSS Feeds, Social Bookmarks

12.Article Directories, syndicate

13.Circular SEO, links to self and others back to self.
“The Right Way to … Most People Mess this up big time.”

“Away to instantly… that works everytime.”

“News Flash: Most people don’t realize this”

“A simple… That doubles your …”

“The 4 things you must never do when…”

“I was talking with… and “s

————————————————————————————

Mark Joiner – Mindcontrolnow.com Use Human psychological factor.

1.How to create video from post.
2.We obey the athority (Burton). Shocks sent that could kill someone.

3.How to use obedience to athority as an affiliate. Establish yourself as an athority in the area, and give a recomendation. The recommendation is higher that just some random person saying they like something. Having an eBook downloaded 1M times established as an athority. Sneeky ways to establish as an athrotiy.  Go do something first, then get someone else to say how good it was.

4.Launch Campain: Buy Copies of their own books (Best Sellers). Dosen’t happen just by chance, their is something deliberatly they did.

5.Books establish you as an athroity.

a.Offer Teaser Material (Target (free product to same market of people who would buy), Tie in (free item to what you will be selling), Connect (Contact info to who collected the freebie))

b.Get a team of affilates to contribute in pre launch.

c.Get other people to say good thing about you.

d.Foot in the door (commit to small thing before submitt to big thing)

e.Feel like they owe you something

f.Demonstrate you are expert

g. Use Graphs and Statistics or Studies

f.”I’m going to tell you who the pitcher for the podreys, but first I’m going to tell you a story”

g. Present Testimonial from other companies first. Then ask for their testimonal as with Name and URL.

6.Your ad has to be done, and used.

7. Powerfull way to sell something as an affiliate, Tell a personal story, depending on the level of athority.

8.Zagarnek effect (headline leaves you wanting more)

Heavy & Deadly Ground:

————————————————-