我有这种格式的标记:-
<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 中显示多种类型的控件?
谢谢。