2014-03-05 59 views
0

因此,我制作了一个asp:日历,并且希望在回发后访问下一页加载时的新选定日期。如何从asp获取新的选定日期:日历

我使用的代码是:

<asp:Calendar ID="calEndDate" runat="server"></asp:Calendar> 

Request.Form[calEndDate.UniqueID] 

,它总是返回null。我能够检索选定的日期,但这会给我以前选择的日期,而不是新的日期。

悬停在“calEndDate”当我得到的消息是:

calEndDate = {SelectedDate = The name 'SelectedData' does not exist in the current context}

任何帮助,将不胜感激。

感谢

+0

因此,从我能够发现有一个与asp:日历控件的问题。有些东西阻止您在回发中抓取detaihttp://connect.microsoft.com/VisualStudio/feedback/details/254459/the-name-selecteddata-does-not-exist-in-the-current-contextls。 – Crypic2009

回答

1

而不是在Page_Load中,使用日历控件的OnSelectionChanged事件,让您选择的日期为:

<asp:Calendar ID="calEndDate" runat="server" 
    OnSelectionChanged="SelectedDate_Change"> 
</asp:Calendar> 

,并选择更改事件是这样的:

void SelectedDate_Change(Object sender, EventArgs e) 
     { 
     Label1.Text = calEndDate.SelectedDate.ToShortDateString(); 
     } 

此外,您使用的日历控件是一个asp.net服务器控件,因此可以使用上面的代码片段中的ID直接访问它,而不是使用Requ est.Form

相关问题