Hi all
i am making a website in visual stusio 2010 and i am using C# with sql server 2008
I have a login page .when the user enters the correct username and password and if the credentials exists in the Sql server database it redirects me to the next page.
i need to populate a label on the redirected page which shows the name of the person who logged in For example the label will show" Welcome Name".
the table which i have in sql server contains the Name,Username and password. how to get the Name from the table to display it in the label on the next page.

Vithal WadjeRank #19 · 47.2K reputationPosted Nov 27, 2012, 6:03 PM EST
Pradip PandeyRank #452 · 5.6K reputationPosted Nov 27, 2012, 9:19 PM EST
//Store value in session object.
Session("UserName") = "User1";
//Get session object value.
string UserName;
UserName = Session("UserName");
Label1.Text = UserName.ToString();
Also refer this link
http://www.c-sharpcorner.com/UploadFile/051e29/session-and-application-in-Asp-Net/
Hope it will help.
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 29, 2012, 2:50 AM EST
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_Page_Using_Stored_Procedure
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlParameter UserName, Password;
protected void btn_login_Click(object sender, EventArgs e)
{
UserName = new SqlParameter();
Password = new SqlParameter();
SqlConnection con = new SqlConnection(strConnString);
com=new SqlCommand();
com.Connection = con;
con.Open();
Session["UserName"] = TextBox_user_name.Text;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "login_pro";
UserName.SqlDbType = SqlDbType.VarChar;
UserName.Size = 50;
UserName.ParameterName = "@UserName";
UserName.Value = TextBox_user_name.Text.ToString();
UserName.Direction = ParameterDirection.Input;
Password.SqlDbType = SqlDbType.VarChar;
Password.Size = 50;
Password.ParameterName = "@Password";
Password.Value = TextBox_password.Text.ToString();
Password.Direction = ParameterDirection.Input;
com.Parameters.Add(UserName);
com.Parameters.Add(Password);
int status;
status = Convert.ToInt16(com.ExecuteScalar());
if (status == 1)
{
Response.Redirect("Welcome.aspx");
}
else
{
lblmessage.Text = "Invalid UserName and Password...";
}
con.Close();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="Login_Page_Using_Stored_Procedure.Welcome" %>
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;
namespace Login_Page_Using_Stored_Procedure
{
public partial class Welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lb1.Text = "WELLCOME :: " + Session["UserName"];
}
}
}