回发后在 Conditional UpdatePanel 中加载不同的控件

发布于 2024-11-01 10:19:14 字数 1236 浏览 3 评论 0原文

我有这种格式的标记:-

 <asp:UpdatePanel runat="server" id="UpdatePanelList" UpdateMode="conditional">
     <ContentTemplate>   
         <asp:ListView></asp:ListView> 
     </ContentTemplate> 
 </asp:UpdatePanel>

 <asp:UpdatePanel runat="server" ID="UpdatePanelMain" UpdateMode="Conditional">
    <ContentTemplate />
 </asp:UpdatePanel> 

在此更新面板中,如果可以找到数据库中的记录,则应显示 DataGrid 控件(带有标签和下拉控件)。如果不是,则应显示 HtmlGenericControl DIV 控件,并显示一条相关消息,要求用户创建记录。这两个控件都是动态创建的,它们使用“输出”函数(如“ToString”)填充自定义类。

如果我使用填充 UpdatePanel 的多个连续 DataGrid 控件来测试操作,则效果很好。类似地,HtmlGenericControl DIV 也会按预期多次连续填充。

但是,当我测试其他控件类型来填充 UpdatePanel 时,这在第一个实例上有效,但是填充 UpdatePanel 的任何其他回发都会失败,并且会出现一个对话框提示:

Failed to load viewstate.  The control tree into which viewstate is being 
loaded must match the control tree that was used to save viewstate during
the previous request.  For example, when adding controls dynamically, the 
controls added during a post-back must match the type and position of the 
controls added during the initial request.

我被引导相信 UpdatePanel 控件控制了视图状态此实例用于动态控件。

如何恢复视图状态以允许多种类型的控件 显示在同一个UpdatePanel中?

谢谢。

I have markup in this format:-

 <asp:UpdatePanel runat="server" id="UpdatePanelList" UpdateMode="conditional">
     <ContentTemplate>   
         <asp:ListView></asp:ListView> 
     </ContentTemplate> 
 </asp:UpdatePanel>

 <asp:UpdatePanel runat="server" ID="UpdatePanelMain" UpdateMode="Conditional">
    <ContentTemplate />
 </asp:UpdatePanel> 

In this update panel, if the record from the database can be found a DataGrid control (with label and dropdown controls) should be displayed. If not a HtmlGenericControl DIV Control should be displayed with a relevant message asking the user to create the record. Both these controls are dynamically created which are populated with custom-built classes using "output" functions like "ToString".

If I test the operation with several successive DataGrid controls populating the UpdatePanel, this works fine. Similarily, the HtmlGenericControl DIV populates as expected also in multiple succession.

However, when I test the other control type to populate the UpdatePanel, this works on the first instance, but any additional postbacks to populate the UpdatePanel fail and a dialogue box prompts:

Failed to load viewstate.  The control tree into which viewstate is being 
loaded must match the control tree that was used to save viewstate during
the previous request.  For example, when adding controls dynamically, the 
controls added during a post-back must match the type and position of the 
controls added during the initial request.

I was led to believe the UpdatePanel Control takes control of the viewstate in this instance for dynamic controls.

How do I restore the viewstate to allow multiple types of controls to be
displayed in the same UpdatePanel?

Thanks.

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

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

发布评论

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

评论(1

飘然心甜 2024-11-08 10:19:14

以与“中生成的最后一个页面相同的层次结构顺序”恢复所有动态控件(将执行此操作的信息保存到 ViewState 或任何确定适当的内容)。 Init”或“Load”生命周期事件。这与 ASP.NET WebForms 中的正常和异步回发的要求相同。

必须添加控件,以匹配控件层次结构,然后在“加载”事件发生后将其删除。

请参阅:

  1. DynamicControlsPlaceholder,它是一个预制控件,可帮助解决此问题。它还讨论了它是如何工作的。
  2. 动态加载 ASP NET 用户控件

Restore all the dynamic controls (save the information to do so to the ViewState, or whatever is determined appropriate) in the same hierarchy order as the last page was generated in the "Init" or "Load" life-cycle events. This is the same requirement for normal and asynchronous post-backs in ASP.NET WebForms.

The controls must be added -- to match the control hierarchy -- and then removed after the "Load" event.

Refer to:

  1. DynamicControlsPlaceholder, which is a pre-made control to help with this. It also discusses how it works.
  2. Dynamic Loading of ASP NET User Controls.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文