Registration Page with Validation To Save Sql

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 924
<table>
<tr>
<td>

FirstName</td>
<td>

<asp:TextBox ID="TxtFname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reg1" runat ="server" ControlToValidate ="TxtFname" ErrorMessage ="*" ValidationGroup ="AddGroup">
</asp:RequiredFieldValidator>

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

LastName</td>
<td>

<asp:TextBox ID="TxtLastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat ="server" ControlToValidate ="TxtLastName" ErrorMessage ="*" ValidationGroup ="AddGroup">
</asp:RequiredFieldValidator>

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

Address</td>
<td>

<asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>


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

ContactNo</td>
<td>

<asp:TextBox ID="TxtContactNo" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat ="server" ControlToValidate ="TxtContactNo" ErrorMessage ="*" ValidationGroup ="AddGroup">
</asp:RequiredFieldValidator>


<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate ="TxtContactNo"
ErrorMessage="RegularExpressionValidator"
ValidationExpression="[0-9]"></asp:RegularExpressionValidator>


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

EmailId</td>
<td>

<asp:TextBox ID="TxtEmailId" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat ="server" ControlToValidate ="TxtEmailId" ErrorMessage ="*" ValidationGroup ="AddGroup">
</asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate ="TxtEmailId"
ErrorMessage="RegularExpressionValidator"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

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

&nbsp;</td>
<td>

<asp:Button ID="Cmd_Submit" runat="server" Text="Save" ValidationGroup ="AddGroup"
onclick="Cmd_Submit_Click" />

</td>
</tr>
</table>


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;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
SqlConnection objconn;
SqlCommand objcmd;
string connStr = ConfigurationManager.ConnectionStrings["Db_Connect"].ToString();
SqlTransaction tran;
SqlDataAdapter objda;
DataSet objds = new DataSet();
DataTable objdt = new DataTable();

protected void Page_Load(object sender, EventArgs e)
{

}
protected void Cmd_Submit_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection(connStr);
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("Insert into Registration(FirstName,LastName,Address,ContactNo,EmailID)values('"+ TxtFname.Text +"','"+ TxtLastName.Text +"','"+ TxtAddress.Text +"','"+ TxtContactNo.Text +"','"+ TxtEmailId.Text +"')",sqlcon);
sqlcmd.ExecuteNonQuery();
}
}

Comments or Responses

Login to post response