Hi,
I would like to know on how to display the logged in username after logging in into the system.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kunal VaishyaRank #990 · 2K reputationPosted May 8, 2012, 12:26 AM EDT
Session["username"]=TextBox1.Text
and
Check if Session.Count > 0 then
Display Username in Label in Webpage
Satyapriya NayakRank #47 · 31.5K reputationPosted May 8, 2012, 12:27 AM EDT
Try this...
<%@ 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
If this post helps you mark it as answer
sheen buhay8 reputationPosted May 8, 2012, 12:49 AM EDT
Krishna GaradRank #191 · 12.8K reputationPosted May 8, 2012, 1:35 AM EDT
buttonlogin_Click(..)
{
//your logic to check username and pwd
//declare one variable in home page with public modifier
homepage obj=new homepage();
obj.username=textboxusername.Text;
obj.show();
this.hide()
)
may helps you
Kunal VaishyaRank #990 · 2K reputationPosted May 8, 2012, 2:05 AM EDT
You can use Public String Variable to store UseName and after successfully login Disply in veriable value in to label if desktop application you can also use toolstrip menu label to display
best way if you use MDI Form