what my code ‘below’ does is: the client javascript calls a webservice method which creates a generic list and then stores it into a session.
[WebMethod(EnableSession = true)]
public void SaveUserSelection(string slctdRooms, string slctdcst)
{
List<SelectRms> SelectR = Session["someinfo"] as List<SelectRms>;
if (SelectR == null)
{
SelectR = new List<SelectRms>();
Session["someinfo"] = SelectR;
}
SelectR.Add(new SelectRms { roomtype = slctdRooms, Roomcst = slctdcst });
}
I would then retreave the session to show the data in another page like this
List(SlctdRmWebSrv.SelectRms) SelctdRM = (List(SlctdRmWebSrv.SelectRms))Sessio[“someinfo”];
if(SelctdRM != null)
{
repeater1.DataSource = SelctdRM;
repeater1.DataBind();
}
the problem is that every time I retreave the session to create a new list, the new data is added up to the old one. I want to have a situation where only the current data is displayed. I tried to clear the list, abandon the session, or clear the repeater before adding the new ones it did hehlp; easy there an easy way to get this done. many thanks
It sounds like you are calling
SaveUserSelectionmultiple times from your javascript. If that’s the case then only the very first time your list will be initialized.Therefore, your list will keep adding stuff to the “old” list since the list has not been cleared or re-initialized .
You should probably put the initialization in a separate method (either on
Page_Loador create a newWebMethodjust to clear/initialized the list). For example, this is how it looks if you decide to put it on thePage_Loadevent:Note: code no tested
This is how it looks if you create a
WebMethod:Call this method when you are ready to keep track of the user selection. Perhaps when your form initially loads (place this script at the bottom of the page):
So
SaveUserSelectionwill look like this:And this is how your javascript looks like whenever your selection changes: