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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal VaishyaPosted May 8, 2012, 6:05 AM
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
Krishna GaradPosted May 8, 2012, 5:35 AM
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
sheen buhayPosted May 8, 2012, 4:49 AM
Satyapriya NayakPosted May 8, 2012, 4:27 AM
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
Kunal VaishyaPosted May 8, 2012, 4:26 AM
Session["username"]=TextBox1.Text
and
Check if Session.Count > 0 then
Display Username in Label in Webpage