Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
C#
if (IsPostBack)
{
 AttendanceDate = DateTime.Parse(HttpContext.Current.Session["AttendanceLogDate"].ToString()); 
}
else
{
 AttendanceDate = Convert.ToDateTime(HttpContext.Current.Session["AttendanceLogDate"].ToString());
}

The above code is working fine. Please clarify me that why this conversion requires postbacks.

Now, I have changed my working machine,VS2012. Now the above code is not working and throws "string is not valid datetime".
Posted

1 solution

use below code :

C#
DateTime tempDate;
if (HttpContext.Current.Session["AttendanceLogDate"] != null && DateTime.TryParse(HttpContext.Current.Session["AttendanceLogDate"].ToString(), out tempDate))
{
  AttendanceDate = tempDate;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900