客户端在运行时填充服务器集合

问题描述:

每当客户端在日历控件上选择日期时,我将添加到服务器上的DateTime对象列表中,然后突出显示控件上的所有选定日期。我可以突出显示在页面加载列表中实例化的日期以及客户端选择的第一个日期。然而,在控件上进一步的日期选择只是改变哪个日期被突出显示,即。不突出更多。客户端在运行时填充服务器集合

我已经通过在选择在运行时将所选择的DateTime对象列表,然后将他们每个人的日历“选择日期”,认为房地产会得到解决的日历控件结算上选择SelectedDates财产的问题一个新的日期。通过打印日期列表中的所有日期进行调试通过文本框显示列表实例化的日期,最新的选择仅在列表中,而不是先前的选择。我的问题和我认为的问题, 服务器上的列表可以在运行时由客户端的操作填充,并添加到? 我在VS2008上使用ASP和C#.Net3.5。 谢谢

我的代码 System.Collections.Generic.List dates;

protected void Page_Load(object sender, EventArgs e) { 
     this.dates = new List<DateTime>(); 
     this.dates.Add(new DateTime(2009,12,2)); 
     this.dates.Add(new DateTime(2009, 12, 3)); 
     this.dates.Add(new DateTime(2009, 12, 16)); 
     fillDates(); 
    } 

    protected void AvailCalender_SelectionChanged(object sender, EventArgs e){ 
     this.dates.Add(this.AvailCalender.SelectedDate); 
     foreach (DateTime date in this.dates) 
     { 
      this.AvailCalender.SelectedDates.Add(date); 
      this.displayText.Text = this.displayText.Text + date.ToShortDateString(); 
     } 
     fillDates(); 
    } 


    protected void fillDates() 
    { 
     foreach (DateTime dates in this.dates) 
     { 
      this.AvailCalender.SelectedDates.Add(dates); 
     } 
     this.AvailCalender.SelectedDayStyle.BackColor = System.Drawing.Color.Blue; 
    } 

List<DateTime>正在创建每个回发,因此它不保存以前的选择。您需要以某种方式坚持它,例如使用ViewState,Session或将其存储在数据库中。只有在第一次使用Page.IsPostBack来检查这是否是该页面第一次被击中时才创建。