Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
first i create a table login and fields as follows;
table name login
Loginid,Firstname,Lastname,Password and Lastlogin.
1 ram sam 123 8/12/2012 11:30
then i create loginpage design as follows;
 
username txtusername.text
 
Password txtpassword.text
 
in that run page when i type 1 in username and 123 in password and click the button it shows the message validloginid and password. and when i type some value in username and password it shows loginid and password does not match.
 
it is working.
 
for that code has follows;
 
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Data.SqlClient;
 
public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection("Data Source=MOORTHY;Initial Catalog=master;Integrated Security=True ");
    protected void Page_Load(object sender, EventArgs e)
    {
              
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select Loginid,Password from entry where Loginid = '" + txt_username.Text + " ' and Password = '" + txt_password.Text + "'",con);
        SqlDataReader dr = cmd.ExecuteReader();
        if(dr.HasRows)
        {
            Session["Loginid"] = txt_username.Text ;
            dr.Close();
            con.Close();
            Label3.Text = "Valid Login ID  and Password";
            Label3.ForeColor = System.Drawing.Color.DarkGreen;
            //Server.Transfer("default2.aspx");
        }
        else
        {
            Label3.Text = "Login ID  Does Not Match";
            Label3.ForeColor = System.Drawing.Color.DarkOrange;
 
        }
 
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        txt_username.Text = "";
        txt_password.Text = "";
        Label3.Text = "";
    }
}
 
then i design the next page design as follows;
 
Firstname textbox1
Lastname textbox2
 
when i click the login page it goes to next page in that page
 
Firstname ram (value from the login table to be retrieve)
Lastname sam (value from the login table to be retrieve)
Posted 9-Dec-12 18:54pm
Edited 9-Dec-12 19:03pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
You have multiple option to do this.
 
Retrieve the user information in login page and pass that information through below technique.

1. Query String
2. Use session object
 
Update your code as below.
protected void Button1_Click(object sender, EventArgs e)
{
        con.Open();
        SqlCommand cmd = new SqlCommand("select Firstname,Lastname from entry where Loginid = '" + txt_username.Text + " ' and Password = '" + txt_password.Text + "'",con);
        SqlDataReader dr = cmd.ExecuteReader();
        if(dr.HasRows)
        {
            dr.Read();
            Session["FNAME"] = dr["Firstname"].ToString();
            Session["FNAME"] = dr["Lastname"].ToString();
            
            dr.Close();
            con.Close();
            Label3.Text = "Valid Login ID  and Password";
            Label3.ForeColor = System.Drawing.Color.DarkGreen;
            Server.Transfer("default2.aspx");
        }
        else
        {
            Label3.Text = "Login ID  Does Not Match";
            Label3.ForeColor = System.Drawing.Color.DarkOrange;
 
        }
 
    }
 
Access Session value in default page2's page load or any other page.
 
Or
 
Pass first name and last name in query string.
 
dr.Read();
fName = dr["Firstname"].ToString();
lName = dr["Lastname"].ToString();
Server.Transfer("default2.aspx?FNAME="+fName+"&LNAME="+lName);
 
Or
 
Pass user ID to next page and retrieve user information from the DB in next page.
 
Hope this will help you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use query string :
 int L_id= // fetch login id from table where name= txt_username
Server.Transfer("default2.aspx?loginid="L_id);
 
//and on second page:

// onpageload:
 
int L_id=Convert.ToInt(Request.QueryString["L_id"]);
//fetch your first name and last name using this L_id
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,858
1 Tadit Dash 330
2 OriginalGriff 278
3 Sergey Alexandrovich Kryukov 275
4 Manas Bhardwaj 249
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,711
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid