Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:50:59+00:00 2026-06-02T22:50:59+00:00

what my code ‘below’ does is: the client javascript calls a webservice method which

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:51:11+00:00Added an answer on June 2, 2026 at 10:51 pm

    It sounds like you are calling SaveUserSelection multiple 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_Load or create a new WebMethod just to clear/initialized the list). For example, this is how it looks if you decide to put it on the Page_Load event:

    Note: code no tested

    private void Page_Load(object sender, System.EventArgs e)
    {
      if(!Page.IsPostBack)
        Session["someinfo"] =  new List<SelectRms>();  
    }
    

    This is how it looks if you create a WebMethod:

    [WebMethod(EnableSession = true)]
    public void InitUserSelection()
    {
      Session["someinfo"] =  new List<SelectRms>();
    }
    

    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):

    $(document).ready(function() {
      $.ajax({
      type: "POST",
      url: "PageName.aspx/InitUserSelection",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
        // After init you could use this method to do something else
      }
    });
    });
    

    So SaveUserSelection will look like this:

    [WebMethod(EnableSession = true)]
    public void SaveUserSelection(string slctdRooms, string slctdcst)
    {
      List<SelectRms> SelectR = Session["someinfo"] as List<SelectRms>;
      if (SelectR  != null)
        SelectR.Add(new SelectRms { roomtype = slctdRooms, Roomcst = slctdcst });
    }
    

    And this is how your javascript looks like whenever your selection changes:

    $.ajax({
      type: "POST",
      url: "PageName.aspx/SaveUserSelection",
      data: "{'slctdRooms':'Value1','slctdcst':'Value2'}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
       //your list was updated, you may do something afterwards
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code below works well on Firefox - displays progress bar which progresses on every
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code static void MyClass::ThreadEntryStatic() { //... } void MyClass::Begin() { CreateThread(..,ThreadEntryStatic,..); } In which
Code for server: http://stikked.com/view/64826511 Network Code for client: http://stikked.com/view/38974838 Basically, the client connects to
//CODE $entries = $model->fetchEntries(); $feedUri = '/rss/'; //link from which feed is available $link
Code Snippet: ShippingPeriod[] arrShippingPeriods; . . . List<ShippingPeriod> shippingPeriods = ShippingPeriodList.ToList<ShippingPeriod>(); The Last line
Code below sets default values for new row if row is added using form.
I was writing code for dragging mechanism which invokes to wait for small period
Code for webpage such that if anyone closes it, then next time when he
Code is below, when I hit the page with: http://ryan.local.testmode.com/timecrunch/bctimepost.ashx?project=2593059&person=2831215&date=04/16/2009&hours=2.5&case=555 it just sort of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.