To enable a session, we must use [WebMethod (enableSession: true)]
[WebMethod(EnableSession=true)] public string saveName(string name) { List<string> li; if (Session["Name"] == null) { Session["Name"] = name; return "Data saved successfully."; } else { Session["Name"] = Session["Name"] + "," + name; return "Data saved successfully."; } }
Now, to get these names using a session, we can go like this:
[WebMethod(EnableSession = true)] public List<string> Display() { List<string> li1 = new List<string>(); if (Session["Name"] == null) { li1.Add("No record to display"); return li1; } else { string[] names = Session["Name"].ToString().Split(','); foreach(string s in names) { li1.Add(s); } return li1; } }
so he will select all the names from the session and show.
Debendra Dash Nov 10 '16 at 9:50 2016-11-10 09:50
source share