I read How to convert query result to list. But it not work or I don't know how to use it in my case.
My scenario is I have login page when user write email and password, application fetch data based on email and password.
protected void lbtnSignIn_Click(object sender, EventArgs e)
{
try
{
SiteDataContext dc = new SiteDataContext();
Session["UserData"] = from data in dc.Users
where data.Email.Equals(txtEmail.Text.ToString()) &&
data.Password.Equals(txtPassword.Text.ToString())
select data;
Response.Redirect("SignIn.aspx");
}
catch(Exception exp)
{
lblMessage.Visible = true;
lblMessage.Text = exp.Message;
}
}
I save LINQ query result in Session["UserData"]
and redirect to another page. On second page I want to get session result and show user data on page.
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
var data = Session["UserData"];
lblName.Text = data.Name;
}
}
I can't get data from object data. It gives me below error
Object does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a directive or an assembly reference?)
Simply I want to show data of login user on another webpage. Please help.