2016-07-22 82 views
0

我目前正在运行UpdatePanel的问题。我的一个页面有两个用户控件,我会打电话给A和B.用户控制,委托和UpdatePanel问题

用户控件A有一个包含几个ASP TextBox的UpdatePanel。

<asp:UpdatePanel ID="upA" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" style="position: relative;"> 
    <ContentTemplate> 
     <-- content here --> 
    </ContentTemplate> 
</asp:UpdatePanel> 

用户控件B具有包含面板和链接到它的AjaxModalPopup一个UpdatePanel。在面板中,有一个Repeater和一个ASP按钮。

<asp:UpdatePanel runat="server" ID="upB" UpdateMode="Conditional"> 
<ContentTemplate> 
    <asp:Button ID="btnActivePopupContainer" runat="server" Style="display: none;" /> 
    <asp:Panel ID="pnlPopupContainer" runat="server" CssClass="modalPopup modalPopupDraggable" Style="display: none;" Width="750px"> 
     <asp:UpdatePanel ID="upPopup" runat="server" UpdateMode="Conditional"> 
      <ContentTemplate> 
       <asp:Panel runat="server" ID="pnlHeader" class="header"> 
        <asp:Label ID="Label1" runat="server" Text="<%$ Resources:global, AttentionPopup %>"></asp:Label> 
       </asp:Panel> 
       <article> 
        <asp:Repeater runat="server" ID="rptPopup" OnItemDataBound="rptPopup_ItemDataBound"> 
         <ItemTemplate> 
          <-- Content --> 
         </ItemTemplate> 
        </asp:Repeater> 
       </article> 
       <footer> 
        <div class="or-spacer"> 
         <div class="mask"></div> 
        </div> 
        <div class="footer"> 
         <asp:Panel runat="server" ID="pnlBtnBug"> 
          <asp:Button ID="btnOK" runat="server" CssClass="btn yes" Text="<%$ Resources:global, Ok %>" OnClick="btnOK_Click" /> 
         </asp:Panel> 
        </div> 
       </footer> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
    </asp:Panel> 
    <ajax:ModalPopupExtender ID="popupContainer" runat="server" BackgroundCssClass="modalBackground" PopupControlID="pnlPopupContainer" TargetControlID="btnActivePopupContainer" Drag="true" PopupDragHandleControlID="pnlHeader"></ajax:ModalPopupExtender> 
</ContentTemplate> 

当用户点击该用户控件B的确定按钮时,它触发调用在用户控件A中的方法,其执行某些字段的更新和在UpdatePanel“UPA的更新方法的委托”。

委托:

//Delegate Call When the user clicks the ok Button 
popup.okHandler = (x) => 
{ 
    A.ChooseOpticienCode(x.Value); 
}; 

背后的用户控件A的代码:

public void ChooseOpticienCode(string code) 
{ 
    <-- some treatments -- > 
    upOpticien.Update(); <-- crash here 
} 

当方法upOpticien.Update()被调用时,我得到这个错误:

System.InvalidOperationException: The Update method can only be called on UpdatePanel with ID 'upOpticien before Render. 

我不明白为什么我会得到这个错误。我试图将UpdatePanel的UpdateMode设置为“始终”,应用程序不再崩溃,但字段没有更新。

想法?

+0

你为什么要手动更新UpdatePanel而不是为它设置触发器?无论如何,它看起来像错误告诉你,你不能在页面生命周期的那一部分运行.Update()方法。您应该尝试查找/阅读关于该方法的文档。 – Seano666

+0

我尝试手动更新它,因为它在后面的代码中,我更改了UpdatePanel包含的所有文本框的值。 因此,由于在代码隐藏中修改了值,因此不会启动任何事件,因此触发器在此处不再需要。 – TheNawaKer

回答

0

我终于找到了如何解决我的问题。而不是直接调用委托的,我必须使用,以便正确地执行委托InvokeMember功能,可以编辑各个领域和更新的UpdatePanel

page.GetType().InvokeMember(OkHandler.Method.Name, System.Reflection.BindingFlags.InvokeMethod, null, page, new[] { this }); 

(这里,OkHandler是我的代表)

然而请注意,使用匿名方法将不起作用,因此委托人必须指向具有InvokeMember名称的方法。