1. That's a totally wrong code:
try
{
if (ViewState[_lstDataSource"] == null)
ViewState[_lstDataSource"] = null;
}
catch (Exception ex)
{
throw ex;
}
Why? If
ViewState["_lstDataSource"]
is already
null
, there is no need to set it to null. And a
catch (Exception ex) { throw ex; }
without anything else just destroys the callstack information of the original exception, it does not add any information or offer any help.
2. The source fo your problem is somewhere else. Where is the type of
_lstDataSource
defined? There you have to add an attribute, something like
[Serializable]
public class SomeType