using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace UsingServerControls
{
	/// <summary>
	/// Summary description for CustomValidator.
	/// </summary>
	public class CustomValidator : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox Name;
		protected System.Web.UI.WebControls.TextBox Email;
		protected System.Web.UI.WebControls.TextBox PhoneNumber;
		protected System.Web.UI.WebControls.Button SubmitBtn;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.CustomValidator RequiredFieldsValidator;
		protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
		protected WebControlLibrary1.WebCustomControl1 WebCustomControl11;
		protected WebControlLibrary1.WebCustomControl1 WebCustomControl12;
		protected System.Web.UI.WebControls.Label	WelcomeInfo;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.SubmitBtn.Click += new System.EventHandler(this.SubmitBtn_Click);
			this.RequiredFieldsValidator.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.RequiredFieldsValidator_ServerValidate);
			this.Load += new System.EventHandler(this.Page_Load);
			this.Init += new System.EventHandler(this.Page_Init);

		}
		#endregion

		private void RequiredFieldsValidator_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
		{
			if (("" == this.Email.Text) && ("" == this.PhoneNumber.Text))
				args.IsValid = false;
			else
				args.IsValid = true;
		}

		private void Page_Init(object source, System.EventArgs e)
		{		
			// Put user code to initialize the page here
			#region Dynamically creating Web UI by accessing control tree
			this.WelcomeInfo = new Label();
			WelcomeInfo.Text = "Welcome !";
			this.Page.Controls.Add(WelcomeInfo);
			#endregion
		}

		private void SubmitBtn_Click(object sender, System.EventArgs e)
		{
			this.WelcomeInfo.Text = "Welcome  " + this.Name.Text + "!";
		}
	}
}
