【问题标题】:User control CalendarPopup inside a GridView is not refreshed when inside an UpdatePanel在 UpdatePanel 内时,不会刷新 GridView 内的用户控件 CalendarPopup
【发布时间】:2015-03-20 06:09:26
【问题描述】:

我在 UpdatePanel 内的 GridView 内使用 eWorldUI 日历弹出窗口(底部链接)。

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

我的问题是:

GridView 控件“在 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其实是在&lt;form&gt;里面,但是是在UpdatePanel外面添加的。这并不明显,因为如您所见,一切都出现在 UpdatePanel 中。所以为了测试它,我在 UpdatePanel 之外添加了一个&lt;div class="outsideUpdatePanel"&gt;&lt;/div&gt;,当在 Chrome 中启动并检查 HTML 时,我可以看到生成的日历 HTML 出现在我的新 div 之后。

【问题讨论】:

  • 对不起,如果它看起来很具体,我可以用任何控件问同样的问题,所以答案不一定是关于日历的。

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


【解决方案1】:

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

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

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

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

【讨论】:

  • 是的,我的表中确实有一列等于 ID。这也是我读到的关于生命周期的内容,所以我目前看到的唯一原因是它一定意味着日历控件的html没有添加到UpdatePanel中。
  • 我还没有解决我的问题,但你的帖子确实回答了我的问题。现在我知道它为什么不更新了,所以我会根据所采取的步骤更新我的帖子。
  • 我看不到控件的任何绑定,这意味着我看不到控件填充关联的文本框,反之亦然以显示用户选择的起点...今天的日期或类似的东西。这一切都在背后的代码中进行管理吗?
  • 是的,很抱歉我不能放这部分代码,因为那里有点乱,但是所有的绑定都可以正常工作。我已经更新了我的帖子。
  • 仅供参考 - jquery 可以轻松移动 DOM 对象。我必须做一些类似的事情才能使 ColorBox(第三方弹出窗口)与 ASP.NET 一起工作。这会将在表单外部呈现的 2 个 div 移动到表单底部:$("#colorbox, #cboxOverlay").appendTo('form:first');.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-08
  • 1970-01-01
相关资源
最近更新 更多