【问题标题】:How to get the new selected date from asp:calendar如何从 asp:calendar 获取新的选定日期
【发布时间】:2014-03-05 22:46:43
【问题描述】:

所以我制作了一个 asp:calendar,并且我想在回发后在下一页加载时访问新选择的日期。

我使用的代码是:

<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}

对此的任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 所以从我发现的情况来看,asp:calendar 控件存在问题。有些东西会阻止您在回发时获取详细信息http://connect.microsoft.com/VisualStudio/feedback/details/254459/the-name-selecteddata-does-not-exist-in-the-current-contextls。

标签: jquery asp.net calendar autopostback


【解决方案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();
      }

此外,您使用的 Calendar 控件是一个 asp.net 服务器控件,因此请使用其 ID 直接访问它,如上面的代码 sn-p 而不是使用 Request.Form

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多