JQuery DatePicker 未在部分回发时保存正确的日期

发布于 2024-09-06 22:19:16 字数 941 浏览 4 评论 0原文

所以我有一些文本框(在用户控件中 ModalPopup 的 UpdatePanel 中)如下所示:

<asp:TextBox ID="exampleTextBox" runat="server" MaxLength="10" 
    CssClass="datepicker" ReadOnly=true 
    Text='<%# Bind("ExampleDateField") %>' Width="77px">
</asp:TextBox>

我还有一些 jQuery(从母版页上的文件导入),它们连接 jQuery DatePickers,如下所示:

function pageLoad() {
    $(".datepicker").unbind();
    $(".datepicker").datepicker({
        changeMonth: true,
        changeYear: true,
        showOtherMonths: true,
        selectOtherMonths: true,
        beforeShowDay: $.datepicker.noWeekends,
        showOn: 'button',
        buttonImage: '../Resources/Images/Calendar_scheduleHS.gif',
        buttonImageOnly: true,
        buttonText: 'Select a Date'
    });
}

DatePickers 显示正确,即使在回发之后。

问题是发生回发时文本框的值不会更改。这很奇怪,因为文本框显示了浏览器中选定的日期。但是,文本框的值仍然是文本框最初具有的日期,而不是从日期选择器中选择的日期。

有什么想法为什么我无法获得选定的日期吗?

So I have some textboxes (in an UpdatePanel in a ModalPopup in a User Control) that look like this:

<asp:TextBox ID="exampleTextBox" runat="server" MaxLength="10" 
    CssClass="datepicker" ReadOnly=true 
    Text='<%# Bind("ExampleDateField") %>' Width="77px">
</asp:TextBox>

I also have some jQuery (imported from file on the Master page) that hooks up the jQuery DatePickers like so:

function pageLoad() {
    $(".datepicker").unbind();
    $(".datepicker").datepicker({
        changeMonth: true,
        changeYear: true,
        showOtherMonths: true,
        selectOtherMonths: true,
        beforeShowDay: $.datepicker.noWeekends,
        showOn: 'button',
        buttonImage: '../Resources/Images/Calendar_scheduleHS.gif',
        buttonImageOnly: true,
        buttonText: 'Select a Date'
    });
}

The DatePickers appear correctly, even after a postback.

The problem is that the value of the textboxes is not changed when a postback occurs. This is very odd since the textbox shows the selected date in the browser. However, the value of the textbox is still the date that the textbox originally had, not the date selected from the datepicker.

Any ideas why I cannot get the selected date?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮世清欢 2024-09-13 22:19:16

这是由于 ReadOnly=true 属性造成的。

把它去掉,或者设置为 false 那么它将使用发布的值

It is due to the ReadOnly=true attribute.

Take that off, or set to false then it will use the posted value

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文