You can write all the validation code using javascript function like
<script language="javascript" type="text/javascript">
function Validation()
{
var txtfirstname1=document.getElementById('<%=txtfirstname.ClientID%>');
var txtlastname1=document.getElementById('<%=txtlastname.ClientID%>');
var txtemail1=document.getElementById('<%=txtemail.ClientID%>');
if(txtfirstname1.value=="")
{
alert("Please Enter Firstname");
txtfirstname1.focus();
return false;
}
if(txtlastname1.value=="")
{
alert("Please Enter Lastname");
txtlastname1.focus();
return false;
}
if(txtemail1.value=="")
{
alert("Please Enter Email");
txtemail1.focus();
return false;
}
var s=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
if(!s.test(txtemail1.value))
{
alert("Enter valid Email");
txtemail1.focus();
return false;
}
}
You can call this function like
<asp:Button ID="Btnsubmit" runat="server" Text="Submit" OnClick="Btnsubmit_Click" OnClientClick="javascript:return Validation()" />
In Submit button click event, write below code
protected void Btnsubmit_Click(object sender, ImageClickEventArgs e)
{
string s = "INSERT into UserDetails (email,firstname,lastname) values('" + txtemail.Text + "','" + txtfirstname.Text + "','" + txtlastname.Text + "')";
SqlCommand cmd;
cn = new SqlConnection(conection.getconnection());
cmd = new SqlCommand(s, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
Here "cn" means your connectionstring variable