在UpdatePanel内部时,用户控件GridView内的CalendarPopup不会刷新

时间:2015-01-21 16:22:49

标签: asp.net ajax gridview webforms user-controls

我在UpdatePanel内的GridView中使用了eWorldUI Calendar Popup(底部链接)。

如果我没有将我的页面表单内容放在UpdatePanel中,那么当我更新Gridview的一行时,日历会被刷新。但是,当所有内容都在UpdatePanel中时,日历不会刷新,因此它始终保留第一行日历的ID。

我的问题是:

GridView控件和#34;在UpdatePanel"之间有什么区别?和"在UpdatePanel"之外并且有什么理由可以解释生成日历HTML的控件事件根本不会发生或者在我更新UpdatePanel中的gridview行之后的恰当时刻发生的事件? 有关解决问题的提示也很感激:)

以下是示例代码(请注意gridview数据源在后面的代码中设置)

<html>
<head> <!-- head stuff --> </head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager id="ScriptManager1" runat="server"></asp:scriptmanager>
<asp:updatepanel id="UpdatePanel1" runat="server"><contenttemplate>
<asp:gridview id="GRIDVIEW1" showheader="False" showfooter="False" runat="server" autogeneratecolumns="false" onrowdatabound="GridView_RowDataBound">                               
<Columns>
    <asp:TemplateField>
        <HeaderTemplate> ...    </HeaderTemplate>
        <HeaderStyle cssclass="..."></HeaderStyle>
        <FooterTemplate> ... </FooterTemplate>
        <FooterStyle cssclass="..."></FooterStyle>
        <EditItemTemplate>
            <asp:textbox id="GRIDVIEW1_DATE1" text="<%# Bind('GRIDVIEW1_DATE1') %>" runat="server"></asp:textbox>
            <ew:calendarpopup imageurl="../../App_Themes/Images/calendar.gif" controldisplay="Image" id="GRIDVIEW1_DATE1_CAL" runat="server"></ew:calendarpopup>
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label id="GRIDVIEW1_DATE1" runat="server" text='<%# Bind("GRIDVIEW1_DATE1") %>'></asp:Label>
        </ItemTemplate>
        <ItemStyle cssclass="..."></ItemStyle>
    </asp:TemplateField>
    <asp:CommandField buttontype="Button" showdeletebutton="True" showeditbutton="True" causesvalidation="False" insertvisible="False"></asp:CommandField>
</Columns>
</asp:gridview>
</contenttemplate></asp:updatepanel>
</form>
</body>
</html>

这是有问题的日历 - http://www.eworldui.net/CustomControls/CalendarPopupDemo.aspx

修改

我发现我的问题实际上是因为日历生成的动态HTML实际上位于<form>内,但是它被添加到UpdatePanel之外。它并不明显,因为正如你所看到的,UpdatePanel内部似乎都有。所以为了测试它,我在UpdatePanel外添加了<div class="outsideUpdatePanel"></div>,当在Chrome中启动并检查HTML时,我可以看到生成的日历HTML出现在我的新div之后。

1 个答案:

答案 0 :(得分:1)

GridView进出Updatepanel没有任何区别。
在这两种情况下都会发生整页生命周期 唯一的区别是只有UpdatePanel的ContentTemplate的内容被传回给浏览器。

您没有指定Gridview DataSourceID属性,因此您必须管理数据绑定。确保在更新后重新绑定GridView。

而且我也要问这个,因为我看不到您的数据源字段列表,但它实际上是否包含一个名为 GRIDVIEW1_DATE1 的字段?我只是想确认你是不是想通过使用它的ID绑定到Gridview TextBox控件

编辑:另外,仅供参考,如果您正在为HTML5开发,您可以将TextBox TextMode属性设置为 Date 并使用现代浏览器的内置日历弹出窗口。 (Text属性必须格式为 yyyy-mm-dd