未捕获的Sys.InvalidOperationException:Sys.InvvalidOperationExcep

本文关键字:Sys InvalidOperationException InvvalidOperationExcep | 更新日期: 2023-09-27 18:25:43

我正在使用ASP.NET构建一个面板应用程序,用户可以在其中更改小部件的位置;为此,我使用了jquery排序表。小部件是动态添加到页面中的ascx(asp.net用户控件)。如果用户没有更改小部件的位置,则小部件中的每个事件都可以正常工作,但如果位置发生了更改,则会出现此错误。

未捕获的Sys.InvalidOperationException:Sys.InvvalidOperationException:找不到ID为"xxx"的UpdatePanel。如果它是动态更新的,那么它必须在另一个UpdatePanel中

这是其中一个小部件的代码,用户可以添加多个实例

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
   <div class="setting" >
   <asp:TextBox ID="txtwidgettitle" runat="server"></asp:TextBox>
      <div id="settingfooter">
         <asp:LinkButton ID="lnkbtnSave" runat="server" onclick="lnkbtnSave_Click">Save</asp:LinkButton>
         <asp:LinkButton ID="lnkbtncancel" runat="server" CssClass="btn ui-state-default ui-corner-all">Cancel</asp:LinkButton>
      </div>
   </div>
</ContentTemplate>
<Triggers>
   <asp:AsyncPostBackTrigger ControlID="lnkbtnSave" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<div class="pcontent">   
  <asp:Literal ID="ltrtwcontent" runat="server"></asp:Literal>
</div>

背后的代码

 protected void Page_Load(object sender, EventArgs e)
{
    ltrtwcontent.Text = jqPlotHelper.RenderChart(CurrentWidgetInstance.Id.ToString());
}
protected void lnkbtnSave_Click(object sender, EventArgs e)
{
    DashboardServices d = new DashboardServices();
    CurrentWidgetInstance.Title = txtwidgettitle.Text;
    CurrentWidgetInstance.LastUpdate = DateTime.Now;
    d.SaveOrUpdateWidgetInstance(CurrentWidgetInstance);
}

在加载控件的aspx页面上,我首先有一个动态添加的容器,该容器将添加小部件实例(ascx控件)

页面上的代码

    protected void Page_Init(object sender, EventArgs e)
    {
        this.SetBasePageVAR(DashboredPageGuid);
        if (this.UsrPage != null)
        {
            phltabs.Controls.Add(LoadDashboardTab());
        }
    }
    public HtmlGenericControl LoadDashboardTab()
    {
       HtmlGenericControl mainList = new HtmlGenericControl("div");
       mainList.Attributes["Id"] = "tabs";
       foreach (WidgetInstance widgetInst in CurrentDashboardTab.WidgetInstances)
       {
         HtmlGenericControl headerList = new HtmlGenericControl("ul");
         WidgetContainerBaseControl widgetContainer = LoadControl("~/Dashboard/WidgetContainer.ascx") as WidgetContainerBaseControl;
         widgetContainer.SetControlVAR(widgetInst);
         headerList.Controls.Add(widgetContainer);
         mainList.Controls.Add(headerList);
       }
       return mainList;
    }

和WidgetContainer.ascx

protected void Page_Init(object sender, EventArgs e)
{
  LoadWidgetInstance();
}
public void LoadWidgetInstance()
{
  WidgetControl widget = LoadControl(CurrentWidgetInstance.Widget.Url) as WidgetControl;
  widget.ID = "wid_" + CurrentWidgetInstance.Id;
  this.phlcontent.Controls.Add(div);
}

未捕获的Sys.InvalidOperationException:Sys.InvvalidOperationExcep

试试这个:像这样添加触发器并删除ASP页面中的触发器

ScriptManager sm = (ScriptManager)Page.Master.FindControl("ScriptManager1");
sm.RegisterPostBackControl(Button);