Search This Blog

22 June 2011

Session State

what is session:

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session.
Session state information is available to all pages opened by a user during single visit. Therefore, you can use session state to store user specific information. If different user are using your application,each user session has a different session state.


how to create session:


Session["name"]=txtname.Text;
//storing the value of textbox in session
Session["name"]="David";
//storing static value in session
or
Session.Add("name",txtname.Text)
Session.Add("name","David")

how to retrieve session value:

string str=Session["name"].ToString();
lbname.Text=Session["name"].ToString();


how
to destroy session's value :

An important consideration for using Session state is that the Session does expire. By default, if a user does not access their Session data within 20 minutes (by default), the Session will expire and all items that had been stored in the Session will be discarded. Because of this, it is important to check the object that is returned from the Session to see if it exists or if it is null before you try to work with it.

if(Session["name"]!=null)
{
lbname.Text=Session["name"].ToString();
}


The Session Timeout is adjustable through a web.config setting but increasing the timeout value can put memory pressure on your server that may be undesirable.



forcefully destroy the session value, other session methods are:
  • Session.Abandon() - removes the Session and all items that it contains
  • Session.Clear() - removes all items from the Session
  • Session.RemoveAll() - removes all items from the Session
  • Session.Remove("itemName") - removes the item that was stored under the name "itemName"



17 June 2011

AutoPostBack Property


Autopostback is the mechanism, by which the page w
ill be posted ,back to the server automatically based on some events in the web controls. In some of the web controls, the property called auto post back, which if set to true, will send the request to the server when an event happens in the control. If this property is set to TRUE the automatic post back is enabled, otherwise FALSE. Default value of AutoPostBack property is FALSE.

For Example



Why we need to set autopostback=true of controls

Consider a scenario where the web page is used for entering the user information. The page contains two dropdownlist controls ddlcountry and ddlstate. When user selects the country, the appropriate states be filled in the ddlstate which is loaded from the database. For achieving this requirement, we can set the autopostback property of ddlcountry to true. If we do that we can handle the event in the server side and write code to populate the ddlstate with the values from the database.
This is how we use the autopostback property.


By default the button,linkbutton and imagebutton has an autopostback as an event. The code behind that you write is to handle this postback. A button cannot have an explicit button postback but is in-built.

How to print the values of Asp controls

lbname.Text= txtname.Text

lbhobby.Text=ddlhobby.SelectedItem.Text //printing text field data

lbhobby.Text=ddlhobby.SelectedItem.Value //printing value field data

lbgender.Text=rdbmale.Text

lbcolor.Text=chkcolor.Text

lbphoto.Text=FileUpload1.Filename

lbid.Text=HiddenField1.Value

31 May 2011

Marquee Property

How to move images in up direction and to start/stop movement whenever cursor on image
<marquee onmouseover="stop()" onmouseout="start()" direction="up">

for speed and behaviour
<marquee scrollamount="4" behavior="alternate">

Width : How wide the marquee is . eg:
<marquee width="200">
hello

Height : How tall the marquee is. eg:
<marquee height="200">
hello
Direction : which direction marquee should scroll. eg: left,right,up,down.
<marquee direction="right">
hello

Behavior : what type of scrolling you want. eg:scroll,slide,alternate
<marquee behavior="scroll">
hello

Scrolldelay : How long to delay between each jump. eg:
<marquee scrolldelay="20">
hello

Scrollamount : How for to jump. eg:
<marquee scrollamount="2">
hello

Loop : How many times to loop.
<marquee loop="2">
hello

BGColor : Background Colour. eg:
<marquee BGColor="yellow">
hello

HSpace : Horizontal space around the marquee. eg:
<marquee HSpace="10">Hello
VSpace : Vertical around the marquee. eg:
<marquee VSpace="10">
hello






HTTP

what is HTTP ?

Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems.Its use for retrieving inter-linked resources led to the establishment of the World Wide Web.


Creation of textboxes with their ids

protected void Button1_Click(object sender, EventArgs e)
{
ArrayList a = new ArrayList();

int j = Convert.ToInt32(TextBox1.Text);
for (int i = 1; i <=j; i++)
{
t = new TextBox();
t.ID = "text" + i; //getting id of control
Form.Controls.Add(t);
a.Add(t.ID);
Response.Write(t.ID);
}

}

09 March 2011

Client side Validations

Client side validation runs in client's browser. For every request code is executed at server side and result is sent to the client in simple HTML format. Its performance is faster than server side validations.

// Create a class file and paste in App_code folder

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public class validation
{
public validation()
{

}
public bool Validate(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf(' {
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate1(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
if (str == "username")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 21)
{
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z'.\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
ctls.BackColor = System.Drawing.Color.White;
return true;
}
public bool Validate2(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "password")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if ((ctls.Text.Trim().Replace("'", "").Length <> 8))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z0-9\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
}
return true;
}
public bool Validate3(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "desc")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 500)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
private bool ValidateDate(string date)
{
try
{
// for US, alter to suit if splitting on hyphen, comma, etc.
string[] dateParts = date.Split('/');

// create new date from the parts; if this does not fail
// the method will return true and the date is valid
DateTime testDate = new
DateTime(Convert.ToInt32(dateParts[2]),
Convert.ToInt32(dateParts[0]),
Convert.ToInt32(dateParts[1]));

return true;
}
catch
{
// if a test date cannot be created, the
// method will return false
return false;
}
}

public bool Validate4(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "address")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 250)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
public bool validateDate(TextBox t1, TextBox t2)
{
bool temp=false;
if (Convert.ToDateTime(t1.Text).CompareTo(Convert.ToDateTime(t2.Text)) > 0)
{
temp=false;
}
else
{
temp = true;
}
return temp;
}

public bool Validate5(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname1")
{
if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 30)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('@') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf(' {
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}) == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate1(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
if (str == "username")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 21)
{
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z'.\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
ctls.BackColor = System.Drawing.Color.White;
return true;
}
public bool Validate2(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "password")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if ((ctls.Text.Trim().Replace("'", "").Length <> 8))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z0-9\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
}
return true;
}
public bool Validate3(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "desc")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 500)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
private bool ValidateDate(string date)
{
try
{
// for US, alter to suit if splitting on hyphen, comma, etc.
string[] dateParts = date.Split('/');

// create new date from the parts; if this does not fail
// the method will return true and the date is valid
DateTime testDate = new
DateTime(Convert.ToInt32(dateParts[2]),
Convert.ToInt32(dateParts[0]),
Convert.ToInt32(dateParts[1]));

return true;
}
catch
{
// if a test date cannot be created, the
// method will return false
return false;
}
}

public bool Validate4(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "address")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 250)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
public bool validateDate(TextBox t1, TextBox t2)
{
bool temp=false;
if (Convert.ToDateTime(t1.Text).CompareTo(Convert.ToDateTime(t2.Text)) > 0)
{
temp=false;
}
else
{
temp = true;
}
return temp;
}

public bool Validate5(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname1")
{
if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 30)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('@') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf('$') == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}) == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}) == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate1(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
if (str == "username")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 21)
{
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z'.\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
ctls.BackColor = System.Drawing.Color.White;
return true;
}
public bool Validate2(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "password")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if ((ctls.Text.Trim().Replace("'", "").Length <> 8))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z0-9\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
}
return true;
}
public bool Validate3(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "desc")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 500)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
private bool ValidateDate(string date)
{
try
{
// for US, alter to suit if splitting on hyphen, comma, etc.
string[] dateParts = date.Split('/');

// create new date from the parts; if this does not fail
// the method will return true and the date is valid
DateTime testDate = new
DateTime(Convert.ToInt32(dateParts[2]),
Convert.ToInt32(dateParts[0]),
Convert.ToInt32(dateParts[1]));

return true;
}
catch
{
// if a test date cannot be created, the
// method will return false
return false;
}
}

public bool Validate4(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "address")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 250)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
public bool validateDate(TextBox t1, TextBox t2)
{
bool temp=false;
if (Convert.ToDateTime(t1.Text).CompareTo(Convert.ToDateTime(t2.Text)) > 0)
{
temp=false;
}
else
{
temp = true;
}
return temp;
}

public bool Validate5(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname1")
{
if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 30)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('@') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf('$') == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}