简体   繁体   English

异步回发后,UpdatePanel中的Obout日历混乱

[英]Obout Calendar in UpdatePanel messes up after asynchronous postback

I am currently trying to implement a date range search function using Obout Calendar controls. 我目前正在尝试使用Obout日历控件实现日期范围搜索功能。 The idea is that the user can select a date from the Obout calendar which will then fill a asp:TextBox beside it. 这个想法是用户可以从Obout日历中选择一个日期,然后将其旁边的asp:TextBox填充。 There are other fields in the form, but this is the one that's breaking. 表单中还有其他字段,但这是一个令人毛骨悚然的字段。 I also have a asp:Button at the bottom of the form who's function is to clear all fields in the form. 我在窗体的底部还有一个asp:Button,其作用是清除窗体中的所有字段。 It does this in the code behind with this: 它在后面的代码中这样做:

protected void btnClearFields_Click(object sender, EventArgs e)
{
    txtFrom.Text = "";
    txtTo.Text = "";
}

And here is the relevant front end code: 这是相关的前端代码:

<table>
    <tr>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <td>
                    <asp:Label ID="lblFrom" runat="server" Text="From:"></asp:Label>
                    <br />
                </td>
                <td>
                    <asp:TextBox ID="txtFrom" runat="server"></asp:TextBox>
                </td>
                <td>
                    <obout:Calendar runat="server" ID="CalendarFrom" TextBoxId="txtFrom" StyleFolder="Calendar/styles/orbitz" ScriptPath="Calendar/calendarscript" DatePickerButtonText <IMG src='Images/calendar.gif' align=absMiddle border=0>" ShowYearSelector="true" DateMin="1/1/1900" AllowDeselect="false" DatePickerMode="true" />
                </td>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                <td>
                    <asp:Label ID="lblTo" runat="server" Text="To:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtTo" runat="server"></asp:TextBox>
                </td>
                <td>
                    <obout:Calendar runat="server" ID="CalendarTo" TextBoxId="txtTo" StyleFolder="Calendar/styles/orbitz" ScriptPath="Calendar/calendarscript" DatePickerButtonText <IMG src='Images/calendar.gif' align=absMiddle border=0>" ShowYearSelector="true" DateMin="1/1/1900" AllowDeselect="false" DatePickerMode="true" />
                </td>
            </ContentTemplate>
        </asp:UpdatePanel>
    </tr>
</table>

Now, the problem I am having is that when I first load the page, all is well. 现在,我遇到的问题是,当我第一次加载页面时,一切都很好。 I can select a date from the calendars and it will fill in the text boxes as expected. 我可以从日历中选择一个日期,它会按预期填写在文本框中。 However, if I click the "Clear Fields" button, which causes a partial postback, then things go wrong. 但是,如果我单击“清除字段”按钮,这会导致部分回发,那么事情就会出错。 When I go to click on the calendar icon again (after the fields have been cleared), the formatting of the date selector that pops up is messed up. 当我再次去点击日历图标(领域已被清除后),日期选择器弹出的格式被搞砸了。 The calendar portion of it is just a red square, can't select any dates. 它的日历部分只是一个红色正方形,无法选择任何日期。 The year selector bar stretches across the entire screen, and changing the year doesn't do anything for the calendar. 年份选择器栏延伸到整个屏幕,更改年份对日历没有任何作用。

I couldn't find any similar problems in my research, so I am not sure what to try. 我在研究中找不到任何类似的问题,所以我不确定该怎么做。 I have tried using only one UpdatePanel around the entire table, but then I get the same problem. 我尝试在整个表周围仅使用一个UpdatePanel,但是随后出现相同的问题。 I have also tried not including the calendar in the UpdatePanels, which will not "break" the calendars, but it will put two new TextBox fields on my webpage (which will accept any new values from the calendar) and not clear the old ones. 我还尝试过不将日历包括在UpdatePanels中,这不会“破坏”日历,但是它将在我的网页上放置两个新的TextBox字段(它将接受日历中的任何新值)并且不会清除旧的字段。 Also tried putting both the button and the table containing the calendar in the same UpdatePanel, but I get the same red box there too. 还尝试将按钮和包含日历的表放在同一UpdatePanel中,但是我在那也得到了相同的红色框。

Found a very similar problem in this answer. 此答案中发现了一个非常相似的问题 I had encountered the problem of my UpdatePanel duplicating contents when I didn't include the Obout calendar in it. 当我没有在其中包含Obout日历时,我遇到了UpdatePanel复制内容的问题。 I fixed this problem by moving my UpdatePanels to surround only the asp:TextBox like so: 我通过将UpdatePanels移动到仅包围asp:TextBox的方式来解决此问题,如下所示:

<td>
    <asp:Label ID="lblFrom" runat="server" Text="From:"></asp:Label>
    <br />
</td>
<td>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="txtFrom" runat="server"></asp:TextBox>
        </ContentTemplate>
    </asp:UpdatePanel>
</td>
<td>
    <obout:Calendar runat="server" ID="CalendarFrom" TextBoxId="txtFrom" StyleFolder="Calendar/styles/orbitz" ScriptPath="Calendar/calendarscript" DatePickerButtonText <IMG src='Images/calendar.gif' align=absMiddle border=0>" ShowYearSelector="true" DateMin="1/1/1900" AllowDeselect="false" DatePickerMode="true" />
</td>

This also meant that I did not have to update the Obout Calendar, which solved the original problem. 这也意味着我不必更新Obout日历,从而解决了原始问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM