回发后在 Conditional UpdatePanel 中加载不同的控件
我有这种格式的标记:-
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以与“中生成的最后一个页面相同的层次结构顺序”恢复所有动态控件(将执行此操作的信息保存到 ViewState 或任何确定适当的内容)。 Init”或“Load”生命周期事件。这与 ASP.NET WebForms 中的正常和异步回发的要求相同。
必须添加控件,以匹配控件层次结构,然后在“加载”事件发生后将其删除。
请参阅:
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: