hi,
i want to create login page with 2 labels for username and password,2text boxes,and 3 buttons for login,signup,cancel.if i press login button means the data's(username,password) are retrived from the sqlserver.and if i click signup means i want to enter some(firstname,lastname,age....) details.i don't know how to i do it.please help me.if i click cancel button means the page is exit from the server.
thanks & regards
gokilavasan
Loading
Satyapriya NayakPosted Mar 29, 2012, 4:56 AM
For sign up
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Register_using_param.WebForm1" %>
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 Register_using_param
{
public partial class WebForm1 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
string str;
SqlCommand cmd;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str="INSERT INTO test VALUES (@amount, @description)";
cmd = new SqlCommand(str,con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@amount", Convert.ToInt64(txt_amount.Text));
cmd.Parameters.AddWithValue("@description", rtxt_description.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
Response.Write("Records Inserted");
}
}
}
For login
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="login_using_parameter._Default" %>
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 login_using_parameter
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
protected void btn_login_Click(object sender, EventArgs e)
{
object obj = null;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select count(*) from login where UserName=@UserName and Password =@Password";
com = new SqlCommand(str, con);
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@UserName", TextBox_user_name.Text);
com.Parameters.AddWithValue("@Password", TextBox_password.Text);
obj = com.ExecuteScalar();
if ((int)(obj) != 0)
{
lb1.Text = "WELLCOME :: " + TextBox_user_name.Text;
}
else
{
lb1.Text = "invalid user name and password";
}
con.Close();
}
}
}
Thanks
gokilavasan mPosted Mar 29, 2012, 7:37 AM
gokilavasan mPosted Mar 29, 2012, 6:29 AM
SenthilkumarPosted Mar 29, 2012, 5:14 AM
Step 1:
Create the sql server table.
Step 2:
Design the login page:
Code File:
Step 3: If they don't have user id then registration page