All pastes #68579 Raw Edit

Mr_

public text v1 · immutable
#68579 ·published 2006-06-21 20:29 UTC
rendered paste body
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace XCWebControls
{

	public class RequiredFieldValidator : System.Web.UI.WebControls.RequiredFieldValidator
	{
		string m_sLabelControl = "";
		string m_sErrorLabelColor = "red";
		string m_sLabelColor = "black";
		bool   m_bUseErrorIndicador = false;
		string m_sErrorIndicator = "* ";
		
		
		public string LabelControl
		{
			get { return m_sLabelControl;  }
			set { m_sLabelControl = value; }
		}	
	
		public string ErrorLabelColor
		{
			get { return m_sErrorLabelColor;  }
			set { m_sErrorLabelColor = value; }
		}
		
		public string LabelColor
		{
			get { return m_sLabelColor;  }
			set { m_sLabelColor = value; }
		}
		
		public string ErrorIndicator
		{
			get { return m_sErrorIndicator;  }
			set { m_sErrorIndicator = value; }
		}
		
		public bool UseErrorIndicator
		{
			get { return m_bUseErrorIndicador;  }
			set { m_bUseErrorIndicador = value; }
		}
		
		protected override bool EvaluateIsValid()
		{
			bool result = base.EvaluateIsValid();
			
			Control control = FindControl(LabelControl);
			if (control != null)
			{
				Label label = control as Label;
				
				if (label != null)
				{				
					string sColorName = result ? LabelColor : ErrorLabelColor;
					label.ForeColor = Color.FromName(sColorName);
					
					if (UseErrorIndicator)
					{
						string sLabelText = label.Text;
												
						if (result)
						{
							if (sLabelText.StartsWith(ErrorIndicator))
							{
								sLabelText = sLabelText.Substring(ErrorIndicator.Length);
							}
						}
						else
						{
							if (!sLabelText.StartsWith(ErrorIndicator))
							{
								sLabelText = ErrorIndicator + sLabelText;
							}
						}
						
						label.Text = sLabelText;
					}
				}
			}
			
			return result;
		}
		
	}
	
	public class CustomValidator : System.Web.UI.WebControls.CustomValidator
	{
		string m_sLabelControl = "";
		string m_sErrorLabelColor = "red";
		string m_sLabelColor = "black";
		bool   m_bUseErrorIndicador = false;
		string m_sErrorIndicator = "* ";
		
		
		public string LabelControl
		{
			get { return m_sLabelControl;  }
			set { m_sLabelControl = value; }
		}	
	
		public string ErrorLabelColor
		{
			get { return m_sErrorLabelColor;  }
			set { m_sErrorLabelColor = value; }
		}
		
		public string LabelColor
		{
			get { return m_sLabelColor;  }
			set { m_sLabelColor = value; }
		}
		
		public string ErrorIndicator
		{
			get { return m_sErrorIndicator;  }
			set { m_sErrorIndicator = value; }
		}
		
		public bool UseErrorIndicator
		{
			get { return m_bUseErrorIndicador;  }
			set { m_bUseErrorIndicador = value; }
		}
		
		protected override bool EvaluateIsValid()
		{
			bool result = base.EvaluateIsValid();
			
			Control control = FindControl(LabelControl);
			if (control != null)
			{
				Label label = control as Label;
				
				if (label != null)
				{				
					string sColorName = result ? LabelColor : ErrorLabelColor;
					label.ForeColor = Color.FromName(sColorName);
					
					if (UseErrorIndicator)
					{
						string sLabelText = label.Text;
												
						if (result)
						{
							if (sLabelText.StartsWith(ErrorIndicator))
							{
								sLabelText = sLabelText.Substring(ErrorIndicator.Length);
							}
						}
						else
						{
							if (!sLabelText.StartsWith(ErrorIndicator))
							{
								sLabelText = ErrorIndicator + sLabelText;
							}
						}
						
						label.Text = sLabelText;
					}
				}
			}
			
			return result;
		}
	
	}
	
}