Hello, Working on this program as to where I need to cultivate this Message to retrieve both the First and Last Name. Working with Cookies with ASP.NET. A simple log in form.
Here is the code to just retrieving the First name that the user inputted; Yes, it does work for just the first name.
//get first name from session state and set welcome message if it exists
string firstName = (string)Session["FirstName"];
if (firstName != null)
{
lblWelcome.Text = "Welcome back, " + (string)Session["FirstName"] + "!";
}
But as I mentioned, I actually need both of the first and last names. And here is my code that I used to try to work this out; but as it would be, it is not retrieving both of them, still just the first name.
//get firstname from cookie and set welcome message if it exists
//HttpCookie cookie = Request.Cookies["FirstName"];
//if (cookie != null)
// lblWelcome.Text = "Welcome back, " + cookie.Value + "!";
//need to get first & last name from session state and set welcome message if it exists
string firstName = (string)Session["FirstName"];
string lastName = (string)Session["LastName"];
if ((firstName != null) && (lastName != null))
{
lblWelcome.Text = "Welcome back, " + (string)Session["FirstName"] + (string)Session[" LastName"] + "!";
}
This is the code behind on my Order.aspx page (snippet)
protected void Page_Load(object sender, EventArgs e)
{
// get entry data from cookies
//if (Request.Cookies["FirstName"] != null)
// txtFirstName.Text = Request.Cookies["FirstName"].Value;
//if (Request.Cookies["LastName"] != null)
// txtLastName.Text = Request.Cookies["LastName"].Value;
//get entry data from session state
if (!IsPostBack)
{
string firstName = (string)Session["FirstName"];
if (firstName != null) txtFirstName.Text = (string)Session["FirstName"];
string lastName = (string)Session["FirstName"]; //my thoughts on this line is that the FirstName should be replaced with ["LastName"]
if (lastName != null) txtLastName.Text = (string)Session["LastName"];
txtFirstName.Focus();
}
}
Would anyone offer me some suggestions as to what I might be doing incorrect?