1. The first part from the 1st solution is OK, you are trying to use something that is not found in the
request
cache.
2.The solution is more simple, just to test with
null
and to get value from the cache that is already a
string
and not to use
ToString()
.
string fromdate1 = (request["from"] == null ? string.Empty : request["from"]);
PS: Note that in the web application caches (like
Session
,
Application
, etc.), the data are saved by using boxing (as objects), than when you get something from cache you should use unboxing and not
ToString()
, like below:
string userName = (string)Session["UserName"];
For more details about boxing and unboxing see in MSDN:
http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx[
^]