ASP.NET Ajax CalendarExtender 将不会更新 SelectedDate 值
由于某种原因,正在处理的 ASP.NET 站点上的任何 CalendarExtender 将不会更新。我已经检查了所有明显的地方(例如 AutoPostBack 和 AutoEventHandler)。问题是,当我从日历中选择一个日期并将其发布到表单时,正在扩展的文本框正在更新,但日历扩展器的日期根本没有被更新(例如 SelectedDate 仍然与以前相同) 。我用谷歌搜索了任何可能的解决方案,但没有一个有效。
这是代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeBehind="ThePage.aspx.cs" Inherits="ThePage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:TextBox runat="server" ID="txtBlah" />
<asp:CalendarExtender ID="txtBlahExtender" runat="server" TargetControlID="txtBlah" Format="MMMM d, yyyy" />
<asp:Button runat="server" ID="btnSubmit" CausesValidation="false" />
和代码隐藏:
public partial class ThePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtBlahExtender.SelectedDate = DateTime.Today.AddDays(4);
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//do postback actions
}
}
}
当我的代码达到“执行回发操作”时,txtBlahExtender.SelectedDate 始终为 DateTime.Today.AddDays(4)。它根本不记录更改。
有什么想法吗?
谢谢, Logain Smith
(是否可以对问题进行格式化?)
For some reason, any CalendarExtenders on an ASP.NET site that is being worked on will not be updated. I have already checked all the obvious places (such as AutoPostBack and AutoEventHandler). The problem is that when I select a date from the Calendar and post it to the form, the TextBox that is being extended IS being updated, but the calendar extender's date is simply not being being updated (e.g. SelectedDate is still the same as before). I have googled for any possible solutions but none have worked.
Here is the code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeBehind="ThePage.aspx.cs" Inherits="ThePage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:TextBox runat="server" ID="txtBlah" />
<asp:CalendarExtender ID="txtBlahExtender" runat="server" TargetControlID="txtBlah" Format="MMMM d, yyyy" />
<asp:Button runat="server" ID="btnSubmit" CausesValidation="false" />
and the codebehind:
public partial class ThePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtBlahExtender.SelectedDate = DateTime.Today.AddDays(4);
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//do postback actions
}
}
}
When my code reaches "do postback actions", txtBlahExtender.SelectedDate is ALWAYS DateTime.Today.AddDays(4). It simply doesn't register the change.
Any ideas?
Thanks,
Logain Smith
(Is it possible to do formatting on a question?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在网上查了无数遍,似乎没有解决这个问题的办法。一个解决方案(如果您想这样称呼它)可能是使用文本框的转换来手动分配 SelectedDate (但这需要您在标记中设置格式):(
其中 blah 是文本控件,blahCalendarExtender 是扩展器等等)
不过,calendarExtender 控件似乎应该足够智能,可以自行完成此操作。
After searching the Internet countless times, there doesn't appear to be a fix for this problem. A solution (if you want to call it that) could be to manually assign SelectedDate using conversion from the textbox (this requires you to set the format in the markup, though):
(Where blah is the Text Control and blahCalendarExtender is the extender extending blah)
It seems that the calendarExtender control should be intelligent enough to do this on its own though.
确保将文本框和扩展器放入 UpdatePanel 中(我在您提供的代码中没有看到这一点)。
Make sure to put the texbox and extender in an UpdatePanel (I don't see this in the code you provided).
我为此找到了一个非常奇怪的解决方案。
不要初始化附加了日历扩展器的文本框的值。将文本框保留为空。
I have found a very strange solution for this.
Do not initialize the value for the textbox which has calendar extender attached. Keep the textbox blank.