2014-03-05 97 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

相關問題