Asp.Net allows the session keys to be used dynamically
both for assigning values to the session keys and for retrieving values from
the session keys.
The normal syntax to assign values to session variables
is
Session["UserID"] = "1";
Session["UserID"] = "1";
However we can also assign values dynamically as follows.
string strUserName = "UserName";
Session[strUserName] = "User1";
The values can also be retireved dynamically as follows
Response.Write("UserID:
" + Session["UserID"].ToString()
+ "<br>");
Response.Write("UserName:
" + Session[strUserName].ToString());
The Output will be
UserID: 1
UserName: User1
UserName: User1
No comments:
Post a Comment