Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • C# signup form code with validation using back-end sqlserver
AuthorQuestion
C# signup form code with validation using back-end sqlserver
Posted By amit singh on 16 Mar 2013
i have label User-id,first-name,last-name,password ,secrete answer and two radio button male and female with one submit and exit button .
please give me accurate answer so that i can understand...


AuthorReply
Re: C# signup form code with validation using back-end sqlserver
Posted By Satyapriya Nayak on 16 Mar 2013  
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Sign_up._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="Label1" runat="server" Text="User id" Width="150px"></asp:Label>
    <asp:TextBox ID="txt_userid" runat="server" Width="150px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="txt_userid" ErrorMessage="userid required"></asp:RequiredFieldValidator>
    <br />
    <asp:Label ID="Label2" runat="server" Text="Firstname" Width="150px"></asp:Label>
    <asp:TextBox ID="txt_firstname" runat="server" Width="150px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
        ControlToValidate="txt_firstname" ErrorMessage="firstname required"></asp:RequiredFieldValidator>
    <br />
    <asp:Label ID="Label3" runat="server" Text="Lastname" Width="150px"></asp:Label>
    <asp:TextBox ID="txt_lastname" runat="server" Width="150px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
        ControlToValidate="txt_lastname" ErrorMessage="lastname required"></asp:RequiredFieldValidator>
    <br />
   
    <asp:Label ID="Label4" runat="server" Text="Password" Width="150px"></asp:Label>
    <asp:TextBox ID="txt_password" runat="server" TextMode="Password" Width="150px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
        ControlToValidate="txt_password" ErrorMessage="password  required"></asp:RequiredFieldValidator>
    <br />
   
    <asp:Label ID="Label5" runat="server" Text="secrete answer" Width="150px"></asp:Label>
    <asp:TextBox ID="txt_secreateanswer" runat="server" Width="150px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
        ControlToValidate="txt_secreateanswer" ErrorMessage="secreteanswer required"></asp:RequiredFieldValidator>
    <br />
     <asp:Label ID="Label6" runat="server" Text="Gender" Width="150px"></asp:Label>
    <asp:RadioButton ID="rb1"  Text="Male" runat="server" />
    <asp:RadioButton ID="rb2"  Text="Female" runat="server" /><br />
    <asp:Button ID="btn_register" runat="server" Text="Register"
        onclick="btn_register_Click" /><br />
    <asp:Button ID="Button2" runat="server" Text="Close" />
    <asp:Label ID="lblmsg" runat="server" Text="Label"></asp:Label>
   
    <div>
   
       
   
    </div>
    </form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Sign_up
{
    public partial class _Default : System.Web.UI.Page
    {
        string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlCommand com;

        protected void btn_register_Click(object sender, EventArgs e)
        {
            if (rb1.Checked == true)
            {
                SqlConnection con = new SqlConnection(strConnString);
                com = new SqlCommand();
                com.Connection = con;
                com.CommandType = CommandType.Text;
                com.CommandText = "insert into register values(@userid,@firstname,@lastname,@password,@secreteanswer,@gender)";
                com.Parameters.Clear();
                com.Parameters.AddWithValue("@userid", txt_userid.Text);
                com.Parameters.AddWithValue("@firstname", txt_firstname.Text);
                com.Parameters.AddWithValue("@lastname", txt_lastname.Text);
                com.Parameters.AddWithValue("@password", txt_password.Text);
                com.Parameters.AddWithValue("@secreteanswer", txt_secreateanswer.Text);
                com.Parameters.AddWithValue("@gender", rb1.Text);
                if (con.State == ConnectionState.Closed)
                    con.Open();
                com.ExecuteNonQuery();
                con.Close();
                lblmsg.Text = "Data entered successfully!!!";
                //clear();
            }
            else
            {
                SqlConnection con = new SqlConnection(strConnString);
                com = new SqlCommand();
                com.Connection = con;
                com.CommandType = CommandType.Text;
                com.CommandText = "insert into register values(@userid,@firstname,@lastname,@password,@secreteanswer,@gender)";
                com.Parameters.Clear();
                com.Parameters.AddWithValue("@userid", txt_userid.Text);
                com.Parameters.AddWithValue("@firstname", txt_firstname.Text);
                com.Parameters.AddWithValue("@lastname", txt_lastname.Text);
                com.Parameters.AddWithValue("@password", txt_password.Text);
                com.Parameters.AddWithValue("@secreteanswer", txt_secreateanswer.Text);
                com.Parameters.AddWithValue("@gender", rb2.Text);
                if (con.State == ConnectionState.Closed)
                    con.Open();
                com.ExecuteNonQuery();
                con.Close();
                lblmsg.Text = "Data entered successfully!!!";
                //clear();
            }
        }
           
    }
}


If this post helps you mark it as answer
Thanks

Re: C# signup form code with validation using back-end sqlserver
Posted By amit singh on 16 Mar 2013  
thanks a lot.
Re: C# signup form code with validation using back-end sqlserver
Posted By amit singh on 16 Mar 2013  
i am doing project in C# with back end sqlserver 2005 .my project is steganography .i have facing problem while creating signup form and sign in also it's validation.pls. check this code and reply with solution if possible,

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.