Reputation: 77
when users login to their account then i show their names and also their designations it works but when i show designation it shows like mix means that username+designation for example JOHNMANAGER .here manager is desgination and same like this happend in my side but i want designations type in brackets. here is code
string desginname = Convert.ToString(loginusers.spdesignname(txt_username.Value, txt_pass.Value));
Session["UserDesignationName"] = desginname;
if (users == 1)
{
Session["Login2"] = txt_username.Value;
Session["Login3"] = txt_pass.Value;
Session["UserDesignationID"] = desginid;
//Session["DepartmentID"] = depid; ;
Session["UserDesignationName"] = desginname;
Session["UserTypeID"] = users;
Response.Redirect("alldocuments.aspx");
}
else if (users == 2)
{
Session["Login2"] = txt_username.Value;
Session["Login3"] = txt_pass.Value;
Session["UserDesignationID"] = desginid;
Session["UserDesignationName"] = desginname;
Session["UserTypeID"] = users;
Response.Redirect("alldocuments.aspx");
}
}
catch
{
errrros.Text = "Incorrect User Name or Password";
}
and here is in site master ...
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["Login2"] != null & Session["UserDesignationName"]!=null)
{
["UserDesignationID"].ToString();
WELCOME.Text = Session["Login2"].ToString() +Session
[("UserDesignationName")].ToString();
}
lbtnLogout.Visible = Session["Login2"] != null || Session["Login2"] !=
null;
}
}
and here is the image image
Upvotes: 3
Views: 122
Reputation: 1003
Just use following line of code if designation name is not supplied.
WELCOME.Text = Session["Login2"].ToString() + (Session["UserDesignationName"].ToString()!="" ? " (" + Session["UserDesignationName"].ToString() + ")" : string.Empty) ;
Upvotes: 0
Reputation: 2788
Try This.
WELCOME.Text = Session["Login2"].ToString() +
" (" + Session["UserDesignationName"].ToString() +")";
Upvotes: 0
Reputation: 41569
Add them in where you build the welcome text:
WELCOME.Text = Session["Login2"].ToString() + " (" + Session
[("UserDesignationName")].ToString() + ")";
or better, use String.Format
:
WELCOME.Text = String.Format("{0} ({1})",
Session["Login2"].ToString(),
Session[("UserDesignationName")].ToString());
Upvotes: 1