Monday, 10 February 2014

Browser Back Button Disable Script

Put this inside of  Head Tag

  <script language="javascript" type="text/javascript">
    window.history.forward();
</script> 

Saturday, 8 February 2014

Floting Social Links Facebook, Twitter, LinkedIn

Put this code between body and form tag


<div id="Div2" style="border: 0px solid #3C95D9;position: fixed ;left: -240px;width: auto;z-index: 10005;top: 235px; left:0px;">
<a href="http:facebook.com/S.raturi89/" target="_blank" >
<img src="images/facebook.png" alt="Facebook" title="Facebook" style="border:0px"></a>
</div>


<div id="Div3" style="border: 0px solid #3C95D9;position: fixed;left: -240px;width: auto;z-index: 10005;top:290px; left:0px;">
<a href="https://twitter.com/sandeep_raturi" target="_blank">
<img src="images/twitter.png" alt="Twitter" title="Twitter" style="border:0px" / ></a>
</div>

<div id="Div4" style="border: 0px solid #3C95D9;position: fixed;left: -240px;width: auto;z-index: 10005;top:330px; left:0px;">
<a href="http://www.linkedin.com/pub/sandeep-raturi/2b/381/b56" target="_blank">
<img src="images/linkedin.png" alt="Linked In" title="Linked In" style="border:0px" /></a>
</div>

Wednesday, 5 February 2014

Help of session shown email id into next page


Database Field


id= int(auot increment and primary key) 
username=varchar(50) 
password=varchar(50) 

//sessionexample.aspx 

<div> 
<pre> 
Email: <asp:TextBox ID="name" runat="server"></asp:TextBox> 
password:<asp:TextBox ID="pass" runat="server" TextMode="Password"></asp:TextBox> 
<asp:Button ID="btn" runat="server" Text="login" 
onclick="btn_Click" /> 
</pre> 
</div> 

C# code for sessionexample.aspx 


protected void btn_Click(object sender, EventArgs e) 

SqlDataAdapter dap = new SqlDataAdapter("select * from login where username='"+name.Text+"' and password='"+pass.Text+"'",con); 
DataSet ds = new DataSet(); 
dap.Fill(ds); 
Session["username"] = ds.Tables[0].Rows[0][1].ToString(); 
Response.Redirect("sessionexample2.aspx"); 


now we get the session ,create new page sessionexample2.aspx 

<head> 
<style type="text/css">a {text-decoration: none}</style> 
</head> 

<div> 
<asp:Label ID="lb" runat="server" ForeColor="#6699FF" ></asp:Label> <a href="sessionexample.aspx" style="text-decoration: none; ">logout</a> 
</div> 

C# code for sessionexample2.aspx 


protected void Page_Load(object sender, EventArgs e) 

if (IsPostBack != true) 


lb.Text = Session["username"].ToString(); 


}

How we can send mail in C#??

How we can send mail through C#??

Put this code into head tag

<head runat="server"> 
<title></title> 
<script type="text/javascript"> 
function ok() { 
alert('Your mail has been sent succuessfully'); 

</script> 
</head> 

Put this code into body tag

<div> 
<table align="center"> 
<tr><td>To</td><td><asp:TextBox ID="to" runat="server"></asp:TextBox></td></tr></br> 
<tr> <td> subject</td><td><asp:TextBox ID="sub" runat="server"></asp:TextBox></td></tr></br> 

<tr><td>message</td><td><asp:TextBox ID="message" runat="server" 
TextMode="MultiLine" Height="120px" Width="278px"></asp:TextBox></td></tr></br> 

<tr> <td></td><td><asp:Button ID="btn" runat="server" Text="send" 
onclick="btn_Click" Height="26px" Width="101px" /></td></tr> 
</table> 
</div> 

C# code


using System.Net.Mail; 

protected void clear() 

to.Text = ""; 
sub.Text = ""; 
message.Text = ""; 


protected void btn_Click(object sender, EventArgs e) 

try 

MailMessage mail = new MailMessage(); 
mail.To.Add(to.Text); 
mail.From = new MailAddress("sandeepraturi@gmail.com"); 
mail.Body = message.Text; 
mail.Subject = sub.Text; 
mail.IsBodyHtml = true; 
SmtpClient smtp = new SmtpClient(); 
smtp.Host = "smtp.gmail.com"; 
smtp.Credentials = new System.Net.NetworkCredential 
("sandeepraturi@gmail.com", "*********"); 
smtp.EnableSsl = true; 
smtp.Send(mail); 
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "ok();", true); 

catch 

Response.Write("write correct email id"); 


clear(); 
}

Remove Underline from link


Put this in head tag


<style type="text/css"> 

a {
text-decoration: none 

</style> 

Put this in body tag 


<div> 
<asp:Label ID="lb" runat="server" ForeColor="#6699FF" ></asp:Label> <a href="pagename.aspx" style="text-decoration: none; ">logout</a> 
</div>

Display record in gridview at the time of page load and download picture from gridview


Database Field


Table Name: tb_download 

id= int(auto increment and primary key) 
Name=varchar(50) 
Date=Datetime 
upload=varchar(50) 


Put this code in body tag

<asp:ScriptManager ID="sp" runat="server"></asp:ScriptManager> 
<table> 
<h1>Information</h1> 
<tr><td> 
&nbsp;&nbsp; 
Name:<asp:TextBox ID="txtname" runat="server"></asp:TextBox></td></tr> 
<tr><td> &nbsp;&nbsp;&nbsp; Date:<asp:TextBox ID="txtdate" runat="server"></asp:TextBox><cc1:CalendarExtender 
ID="CalendarExtender1" runat="server" TargetControlID="txtdate"> 
</cc1:CalendarExtender></td></tr> 
<tr><td>Upload:<asp:FileUpload ID="file" runat="server" /></td></tr> 
<tr><td align="center"><asp:Button ID="btn" runat="server" Text="Upload" 
onclick="btn_Click" /></td></tr> 
</table> 
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" 
Height="188px" Width="300px" CellPadding="4" ForeColor="#333333" 
GridLines="None" > 
<AlternatingRowStyle BackColor="White" ForeColor="#284775" /> 
<Columns><asp:TemplateField HeaderText="Name"> 

<ItemTemplate> 

<%#Eval("Name") %> 
</ItemTemplate> 

</asp:TemplateField> 
<asp:TemplateField HeaderText="Date" > 
<ItemTemplate> 
<%#Eval("Date") %> 

</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Download"> 
<ItemTemplate> 
<a href='/upload/<%#Eval("Upload") %>'><%#Eval("Upload") %></a> 

</ItemTemplate> 
</asp:TemplateField> 
</Columns> 
<EditRowStyle BackColor="#999999" /> 
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> 
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> 
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> 
<SortedAscendingCellStyle BackColor="#E9E7E2" /> 
<SortedAscendingHeaderStyle BackColor="#506C8C" /> 
<SortedDescendingCellStyle BackColor="#FFFDF8" /> 
<SortedDescendingHeaderStyle BackColor="#6F8DAE" /> 
</asp:GridView> 


</div> 

C# code

Note: Add upload folder in your project 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data; 
using System.Data.SqlClient; 

namespace sandeep 

public partial class WebForm2 : System.Web.UI.Page 

SqlConnection con = new SqlConnection("server=SANDEEP-PC;database=Example;integrated security=true"); 

protected void Page_Load(object sender, EventArgs e) 

if (IsPostBack != true) 

BindData(); 


protected void btn_Click(object sender, EventArgs e) 



if (file.HasFile) 

String path = Server.MapPath("upload/"); 
String filename = file.FileName; 
file.SaveAs(path + filename); 
SqlCommand cmd = new SqlCommand("insert into tb_download values('" + txtname.Text + "','" + txtdate.Text + "','" +filename + "')", con); 
con.Open(); 
cmd.ExecuteNonQuery(); 
clear(); 
con.Close(); 
BindData(); 



protected void clear() 

txtdate.Text = ""; 
txtname.Text = ""; 


protected void BindData() 

SqlDataAdapter dap = new SqlDataAdapter("select * from tb_download ", con); 
DataSet ds = new DataSet(); 
dap.Fill(ds); 

gv.DataSource = ds; 
gv.DataBind(); 




}

Facebook Page Like button Code

Facebook Link Button Code :



Steps are :

Put this code into body tag:

<div > 
<iframe src="https://www.facebook.com/plugins/like.php? 
href=http://www.xyz/Home.aspx&amp;layout=standard&amp;show_faces=true&amp;width=400&amp;action=like&amp;colorscheme=light" 
scrolling="no" frameborder="0" style="border:none; width:250px; height:80px">
</iframe> 
</div> 

Note : write your facebook page link in place of this link http://www.xyz/Home.aspx .

Sunday, 2 February 2014

Simple code for Select Multiple Value from Cheakbox List and save into Database


Database

id = int(auto increment,primary key) 
chk = varchar(50) 


Put this code in body tag 

<body> 
<form id="form1" runat="server"> 
<div align="center"> 
<h1 align="center">Select Name</h1> 
<asp:CheckBoxList ID="Chk" runat="server"> 
<asp:ListItem>Sandeep</asp:ListItem> 
<asp:ListItem>Dinesh</asp:ListItem> 
<asp:ListItem>Pradeep</asp:ListItem> 
<asp:ListItem>Kuldeep</asp:ListItem> 
</asp:CheckBoxList> 
<asp:Button ID="btn" runat="server" Text="submit" onclick="btn_Click" /></div> 
</form> 
</body> 

c# code


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data; 
using System.Data.SqlClient; 

namespace sandeep 

public partial class WebForm2 : System.Web.UI.Page 

SqlConnection con = new SqlConnection("server=SANDEEP-PC;Database=data;Integrated Security=True"); 
protected void Page_Load(object sender, EventArgs e) 

if (IsPostBack != true) 





protected void btn_Click(object sender, EventArgs e) 

string str = string.Empty; 

for (int k = 0; k < Chk.Items.Count; k++) 

if (Chk.Items[k].Selected == true) 

str = str + Chk.Items[i].Text + ","; 



con.Open(); 
SqlCommand cmd = new SqlCommand(" insert into chk values ('" +str+ "') " , con); 
cmd.ExecuteNonQuery(); 
con.Close(); 






}

Create Fevicon for your Website


Note: 

1. Create 16x16 px image . 
2. Image Format must be in .ico format... (Example fevicon.ico ) 
3. Add this image into project. 
4. Remind! only .ico format is allowed 



put this inside of head tag


<head runat="server"> 
<title>Sandeep</title> 
<link id="Link1" runat="server" href="fevicon.ico" type="image/x-icon"/> 

</head>

Navigation on DropDownList SelectIndaxChanged Event


put this code inside of body tag

<body> 
<form id="form1" runat="server"> 
<div> 
<h1> Select Profile</h1><br /> 
<asp:DropDownList ID="dl" runat="server" onselectedindexchanged="dl_SelectedIndexChanged" AutoPostBack="true" > 

<asp:ListItem>Slect Profile</asp:ListItem> 
<asp:ListItem>Sandeep</asp:ListItem> 
<asp:ListItem>Pradeep</asp:ListItem> 
<asp:ListItem>Dinesh</asp:ListItem> 

</asp:DropDownList> 
</div> 
</form> 
</body> 


put this inside of DropdownList SelectIndexChanged


protected void dl_SelectedIndexChanged(object sender, EventArgs e) 


if (dl.SelectedItem.Text == "Sandeep") 
Response.Redirect("sandeep.aspx"); 

if (dl.SelectedItem.Text == "Pradeep") 
Response.Redirect("pradeep.aspx"); 

if (dl.SelectedItem.Text == "Dinesh") 
Response.Redirect("dinesh.aspx"); 

}

How we will show data at the runtime help of RadioButtonList SelectIndexChanged Event

put this code inside of body tag

<form id="form1" runat="server">
<div>
<h1>Example</h1>
<table>
<tr><td>Name:</td><td><asp:TextBox ID="name" runat ="server"></asp:TextBox></td></tr>
<tr><td>Age:</td><td><asp:TextBox ID="age" runat="server"></asp:TextBox></td></tr>
<tr><td valign="top">Are you married:</td><td><asp:RadioButtonList ID="RadioButtonList1"
runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" >
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="p1" runat="server">
Marriage date:&nbsp; <asp:TextBox ID="date" runat="server"></asp:TextBox><br />
No. of Children:<asp:TextBox ID="child" runat="server"></asp:TextBox>
</asp:Panel>


</td>


</tr>
</table>

</div>
</form>

 c# Code


protected void Page_Load(object sender, EventArgs e)
{
p1.Visible = false;
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedItem.Text == "Yes")
p1.Visible = true;
else
p1.Visible = false;
}

How we will use THEME in Asp.net


Note: 

1. Firstly add one skin file in your project 

put this code inside of skinfile form (skinfile.skin)


<asp:Label runat="server" BackColor="Yellow" ></asp:Label> 
<asp:TextBox runat="server" ForeColor="Black" BackColor="Yellow"></asp:TextBox> 
<asp:Button runat="server" ForeColor="Black" BackColor="Red" /> 

put this code inside of new form


<body> 
<form id="form1" runat="server"> 
<div> 
<table> 
<tr><td> <asp:Label ID="name" runat="server" Text="Name" ></asp:Label></td><td><asp:TextBox ID="txtname" runat="server" ></asp:TextBox></td></tr> 
<tr><td> <asp:Label ID="fname" runat="server" Text="Father Name"></asp:Label></td><td><asp:TextBox ID="txtfname" runat="server"></asp:TextBox></td></tr> 
<tr><td> <asp:Label ID="add" runat="server" Text="Address"></asp:Label></td><td><asp:TextBox ID="txtadd" runat="server" TextMode="MultiLine"></asp:TextBox></td></tr> 
<tr><td></td><td><asp:Button ID="submit" runat="server" Text="Submit" /><asp:Button ID="cancel" runat="server" Text="Cancel" /></td></tr> 
</table> 

</div> 
</form> 
</body> 

Note: 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Theme.aspx.cs" Inherits="Theme" EnableTheming="true" Theme="SkinFile" %> 

Write following property in this form: 
1. Theme ="SkinFile" // this is theme name 
2. EnableTheming="true"

Submit three dropdownlist value into one database field


Database


Id bigint(Auto increment) 
value varchar(50) 

Html Code


<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>Dropdownlist</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div width="300px" align="center"> 
<br /> 
<br /> 
<br /> 
<asp:DropDownList ID="dd" runat="server"> 
<asp:ListItem>1</asp:ListItem> 
<asp:ListItem>2</asp:ListItem> 
<asp:ListItem>3</asp:ListItem> 
<asp:ListItem>4</asp:ListItem> 
<asp:ListItem>5</asp:ListItem> 
<asp:ListItem>6</asp:ListItem> 
<asp:ListItem></asp:ListItem> 
</asp:DropDownList> 
<asp:DropDownList ID="mm" runat="server"> 
<asp:ListItem>Jan</asp:ListItem> 
<asp:ListItem>Feb</asp:ListItem> 
<asp:ListItem>Mar</asp:ListItem> 
<asp:ListItem>Apr</asp:ListItem> 
<asp:ListItem>May</asp:ListItem> 
<asp:ListItem>Jun</asp:ListItem> 
<asp:ListItem></asp:ListItem> 
</asp:DropDownList> 
<asp:DropDownList ID="yy" runat="server"> 
<asp:ListItem>2010</asp:ListItem> 
<asp:ListItem>2011</asp:ListItem> 
<asp:ListItem>2012</asp:ListItem> 
<asp:ListItem>2013</asp:ListItem> 
<asp:ListItem>2014</asp:ListItem> 
<asp:ListItem>2015</asp:ListItem> 
<asp:ListItem></asp:ListItem> 
</asp:DropDownList> 
<br /> 
<br /> 
<br /> 
</div> 
<div align="center" width="300px"> 
<asp:Button ID="btn" runat="server" Text="Submit" onclick="btn_Click" /> 
<br /> 
</div> 


</form> 
</body> 
</html> 


C# Code

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Data; 

public partial class dropdownlist : System.Web.UI.Page 

SqlConnection con = new SqlConnection("server=SANDEEP-PC;database=data;integrated security=true"); 
protected void Page_Load(object sender, EventArgs e) 




protected void btn_Click(object sender, EventArgs e) 

string s = dd.Text + "/" + mm.Text + "/" + yy.Text; 
SqlCommand cmd = new SqlCommand("insert into dropdown values('"+s+"')",con); 
con.Open(); 
cmd.ExecuteNonQuery(); 
con.Close(); 

}

Language Translator Script

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
<meta name="google-translate-customization" content="c485355c8c754f31-fe3dd5a5cb8710a9-g7f015acebd0dbc42-11" /> 
</head> 
<body> 
<form id="form1" runat="server"> 
<table> 
<tr> 
<td> 
<div id="google_translate_element"></div> 

<script type="text/javascript"> 
function googleTranslateElementInit() { 
new google.translate.TranslateElement({ pageLanguage: 'en', includedLanguages: 'de,es,fr,bn,gu,hi,ja,ta,te,zh-CN', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element'); 

</script> 
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> 

</td> 
</tr> 
</table> 
<div> 
Language Translator code <br /> 


</div> 

Set Focus on TextBox at Page Load

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Set Focus on TextBox</title>
</head>
<body>
<form id="form1" runat="server">
<div align="center" style="width:300px">
<table>
<tr><td>Name:</td><td><asp:TextBox ID="TextBox1" runat="server" TabIndex="0"></asp:TextBox></td></tr>
<tr><td>FName:</td><td><asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox></td></tr>
<tr><td>MName:</td><td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td></tr>
<tr><td>Address:</td><td><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td></tr>
</table>
<br />
</div>
</form>
</body>
</html>

C# Code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class set_focus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Focus();
}
}

Use of Panel in Asp.Net

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Use of Panel</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="rd" runat="server" RepeatDirection="Horizontal" onselectedindexchanged="rd_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem>Student</asp:ListItem>
<asp:ListItem>Employee</asp:ListItem>
</asp:RadioButtonList>

<asp:Panel ID="p1" runat="server">
<table cellpadding="1" cellspacing="2">
<tr><td>Name</td><td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td></tr>
<tr><td>Address</td><td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td></tr>
<tr><td>Qualification</td><td><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td></tr>
<tr><td>Email</td><td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td></tr>
</table>
</asp:Panel>

<asp:Panel ID="p2" runat="server">
<table cellpadding="1" cellspacing="2">
<tr><td>Emp Name</td><td><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td></tr>
<tr><td>Address</td><td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td></tr>
<tr><td>Previous Job</td><td><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td></tr>
<tr><td>Salary</td><td><asp:TextBox ID="TextBox8" runat="server"></asp:TextBox></td></tr>
</table>
</asp:Panel>


</div>
</form>
</body>
</html>

 C# Code 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class panel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
p1.Visible = false;
p2.Visible = false;
}
protected void rd_SelectedIndexChanged(object sender, EventArgs e)
{

if (rd.SelectedItem.Text == "Student")
p1.Visible = true;


if (rd.SelectedItem.Text == "Employee")
p2.Visible = true;
}
}

Validation for Name, Email, contact No.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>Validation in Asp.net</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<table cellpadding="0" cellspacing="0"> 
<tr> 
<td >Full Name<span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox1" runat="server" TabIndex="0" MaxLength="25" ToolTip="Enter your name"></asp:TextBox>&nbsp;&nbsp; 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox1" Display="Dynamic" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="TextBox1" ValidationExpression="^[a-z A-Z]*$" ErrorMessage="Invalid Name" ForeColor="#DA251C" CssClass="validation" Display="dynamic"></asp:RegularExpressionValidator> 
</td> 

</tr> 
<tr> 
<td >Contact no<span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox5" runat="server" MaxLength="10" ToolTip="Enter Contact no."></asp:TextBox> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox5" Display="dynamic" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="rg" runat="server" ControlToValidate="TextBox5" ValidationExpression="^[0-9]{10}$" ErrorMessage=" Invalid No." ForeColor="#DA251C" Display="Dynamic" CssClass="validation" ></asp:RegularExpressionValidator> 
</td> 

</tr> 
<tr> 
<td >E-mail <span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox6" runat="server" MaxLength="25" ToolTip="Enter Your Email Id"></asp:TextBox> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox6" Display="Dynamic" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid E-mail" ForeColor="#DA251C" ControlToValidate="TextBox6" ValidationExpression="^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$" CssClass="validation" ></asp:RegularExpressionValidator> 
</td> 

</tr> 

<tr><td colspan="2"><asp:Button ID="btn" runat="server" Text="Submit" /></td></tr> 

</table> 
</form> 
</body> 
</html>

Watermark on TextBox

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Validation in Asp.net</title>

<script type="text/javascript" language="javascript">
<!--
function doClear(theText) {
if (theText.value == theText.defaultValue) {
theText.value = ""
}
}

function doClear1(theText) {
if (theText.value == "") {
theText.value = theText.defaultValue
}
}
//-->
</script>

</head>
<body>
<form id="form1" runat="server">
<table cellpadding="0" cellspacing="0">
<tr>
<td >Full Name<span style="color:#DA251C">*</span></td>

<td><asp:TextBox ID="TextBox1" runat="server" MaxLength="25" Text="Enter Name" onFocus="doClear(this)" onblur="doClear1(this)"></asp:TextBox>&nbsp;&nbsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox1" Display="Dynamic" CssClass="validation" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="TextBox1" ValidationExpression="^[a-z A-Z]*$" ErrorMessage="Invalid Name" ForeColor="#DA251C" CssClass="validation" Display="dynamic"></asp:RegularExpressionValidator>
</td>

</tr>
<tr>
<td >Contact no<span style="color:#DA251C">*</span></td>

<td><asp:TextBox ID="TextBox5" runat="server" MaxLength="10" Text="Enter Contact" onFocus="doClear(this)" onblur="doClear1(this)" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox5" Display="dynamic" CssClass="validation" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rg" runat="server" ControlToValidate="TextBox5" ValidationExpression="^[0-9]{10}$" ErrorMessage=" Invalid No." ForeColor="#DA251C" Display="Dynamic" CssClass="validation" ></asp:RegularExpressionValidator>
</td>

</tr>
<tr>
<td >E-mail <span style="color:#DA251C">*</span></td>

<td><asp:TextBox ID="TextBox6" runat="server" MaxLength="25" Text="Enter Email" onFocus="doClear(this)" onblur="doClear1(this)"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox6" Display="Dynamic" CssClass="validation" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid E-mail" ForeColor="#DA251C" ControlToValidate="TextBox6" ValidationExpression="^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$" CssClass="validation" ></asp:RegularExpressionValidator>
</td>

</tr>

<tr><td colspan="2"><asp:Button ID="btn" runat="server" Text="Submit" /></td></tr>

</table>
</form>
</body>
</html>

Validation Summery in Asp.net

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>Validation Summery in Asp.net</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<table cellpadding="0" cellspacing="0"> 
<tr> 
<td >Full Name<span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox1" runat="server" MaxLength="25" ></asp:TextBox>&nbsp;&nbsp; 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter Name" ForeColor="#DA251C" ControlToValidate="TextBox1" Display="none" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="TextBox1" ValidationExpression="^[a-z A-Z]*$" ErrorMessage="Invalid Name , Numeric is not allowed" ForeColor="#DA251C" CssClass="validation" Display="none"></asp:RegularExpressionValidator> 
</td> 

</tr> 
<tr> 
<td >Contact no<span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox5" runat="server" MaxLength="10" ></asp:TextBox> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter Contact" ForeColor="#DA251C" ControlToValidate="TextBox5" Display="none" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="rg" runat="server" ControlToValidate="TextBox5" ValidationExpression="^[0-9]{10}$" ErrorMessage=" Invalid No. " ForeColor="#DA251C" Display="none" CssClass="validation" ></asp:RegularExpressionValidator> 
</td> 

</tr> 
<tr> 
<td >E-mail <span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox6" runat="server" MaxLength="25" ></asp:TextBox> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Enter Email" ForeColor="#DA251C" ControlToValidate="TextBox6" Display="none" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid E-mail" ForeColor="#DA251C" ControlToValidate="TextBox6" ValidationExpression="^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$" CssClass="validation" Display="none" ></asp:RegularExpressionValidator> 
</td> 

</tr> 

<tr><td colspan="2"> 

<div style="display:none"> 
<asp:ValidationSummary ID="vs" runat="server" ShowMessageBox="true" /> 

</div> 
</td></tr> 


<tr><td colspan="2"><asp:Button ID="btn" runat="server" Text="Submit" /></td></tr> 

</table> 
</form> 
</body> 
</html>