Tuesday, 25 June 2013

Registration and Login page

Registration

.aspx:

<body>
    <form id="form1" runat="server">
    <div>
     <asp:Panel ID="pnlLogin" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
        Style="margin-top: 14px; margin-left: 40px; height: 400px;">
        <h1>
            Register Here</h1>
        <table>
            <tr>
                <td>
                    <asp:Label ID="uname" runat="server" Text="username"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtuname" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:FileUpload ID="filup" runat="server" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblpsw" runat="server" Text="password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtpsw" runat="server" TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblname" runat="server" Text="Name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblgen" runat="server" Text="Gender"></asp:Label>
                </td>
                <td>
                    <asp:RadioButtonList ID="rblst" runat="server" RepeatDirection="Horizontal">
                        <asp:ListItem Value="0">Male</asp:ListItem>
                        <asp:ListItem Value="1">Female</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lbladd" runat="server" Text="Address"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtadd" runat="server" TextMode="MultiLine"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblstate" runat="server" Text="State"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="ddlst" runat="server" Enabled="true">
                        <asp:ListItem Value="0">Select state</asp:ListItem>
                        <asp:ListItem Value="1">Ap</asp:ListItem>
                        <asp:ListItem Value="2">karnataka</asp:ListItem>
                        <asp:ListItem Value="3">maha</asp:ListItem>
                        <asp:ListItem Value="4">tamil</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblcon" runat="server" Text="Country"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="ddlcou" runat="server" Enabled="true">
                        <asp:ListItem Value="0">Select Country</asp:ListItem>
                        <asp:ListItem Value="1">India</asp:ListItem>
                        <asp:ListItem Value="2">USA</asp:ListItem>
                        <asp:ListItem Value="3">England</asp:ListItem>
                        <asp:ListItem Value="4">China</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblnum" runat="server" Text="PhNum"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtph" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnsub" runat="server" Text="Submit" OnClick="btnsub_click" />
                </td>
                <td>
                    <asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_click" />
                </td>
            </tr>
        </table>
        <br />
        <asp:Label ID="lblmsg" runat="server" ForeColor="Green"></asp:Label>
         <asp:Label ID="lblerr" runat="server" ForeColor="red"></asp:Label>
       
    </asp:Panel>
    </div>
    </form>
</body>


Registration.cs:

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;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["vamsi"].ToString());
    SqlCommand cmd;
    SqlDataAdapter da;
   
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnsub_click(object sender, EventArgs e)
    {
        try
        {
            con.Open();
            string query = "insert into tb_reg([Username],[password] ,[name],[gender],[address],[state],[country],[phonenum],[images])values('" + txtuname.Text + "','" + txtpsw.Text + "','" + txtuname.Text + "','" + rblst.SelectedItem.Text + "','" + txtadd.Text + "','" + ddlst.SelectedItem.Text + "','" + ddlcou.SelectedItem.Text + "','" + txtph.Text + "','"+filup.PostedFile.FileName+"')";
            cmd = new SqlCommand(query,con);
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            string saveimage = Server.MapPath("~\\"+"images") +"\\"+filup.PostedFile;
            con.Close();
            Reset();
            lblmsg.Text="inserted successfully";

           
        }
        catch(Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
     
    }

    private void Reset()
    {
        txtuname.Text = "";
        txtpsw.Text = "";
        txtph.Text = "";
        txtname.Text = "";
        txtadd.Text = "";
        ddlst.SelectedIndex = -1;
        ddlcou.SelectedIndex = -1;
        rblst.SelectedIndex = -1;


    }
    protected void btnReset_click(object sender, EventArgs e)
    {
        Reset();
    }
}



login.aspx 

<body>
    <form id="form1" runat="server">
    <div>
    <asp:Panel ID="pnlLogin" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
        Style="margin-top: 14px; margin-left: 40px; height: 300px;">
        <h1>
            Login Here</h1>
        <table style="margin-top: 30px; margin-left: 50px; height: 105px;">
            <tr>
                <td>
                    <asp:Label ID="lblUsername" runat="server" Text="User name :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblPassword" runat="server" Text="Password :"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnLogin" runat="server" Text="Login"
                        onclick="btnLogin_Click" />
                </td>
                <td>
                    <asp:Button ID="btnReset" runat="server" Text="Reset" onclick="btnReset_Click"  />
                </td>
            </tr>
        </table>
        <br />
        <asp:Label id="lblmsg" runat="server"></asp:Label>
        <asp:Label ID="lblerr" runat="server"></asp:Label>
    </asp:Panel>
    </div>
    </form>
</body>
login.aspx.cs

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;

public partial class login : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["vamsi"].ToString());
    SqlCommand cmd;
    SqlDataAdapter da;
    SqlDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            con.Open();
            String query = "select Username , password from tb_reg where Username='" + txtUsername.Text + "' and password='" + txtPassword.Text + "'";
            cmd = new SqlCommand(query, con);
            cmd.CommandType = CommandType.Text;
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                Response.Redirect("~/welcome.aspx");
            }

            else
            {
                lblerr.Text = "longin failed";
            }
           
            con.Close();
            Resetall();
        }
        catch(Exception ex)
        {
            lblerr.Text = ex.Message;
        }
    }

    private void Resetall()
    {
        txtUsername.Text = "";
        txtPassword.Text = "";
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Resetall();
    }
}
 Welcome.aspx 


<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lab1" runat="server" Text="Welcome to User"  ForeColor="BlueViolet" Font-Size="XX-Large"></asp:Label>
    </div>
    </form>
</body>

 DATABASE:
create database vamsi

create table  tb_reg

(Username varchar(50),password varchar(50),
name varchar(50), gender varchar(50),
address varchar(50),
state varchar(10),country varchar(50),phonenum varchar(50),images varchar(50))

 WEB CONFIG
<connectionStrings>
        <add name="vamsi" connectionString="Data Source=MAIN;Initial Catalog=vamsi;User Id=sa;Password=123; Persist Security Info=true;" providerName="System.Data.SqlClient"/>
       
    </connectionStrings>




 

No comments:

Post a Comment

Receive All Free Updates Via Facebook.