1

我正在设置UpdatePanel1.UpdateMode = UpdatePanelUpdateMode.Conditional;进行手动更新,但它不适用于某些自定义事件,当我在这里有一些类似的事件时:

protected void Button1_Click(object sender, EventArgs e) {
    discovery.FindAlreadyRegisteredServices();
    discovery.discoveryClient.FindCompleted += FoundEvent;

protected void FoundEvent(object sender, FindCompletedEventArgs e) {
    Label1.Text = (discovery.endpoints.Count > 0) ? discovery.endpoints[0].Address.ToString() : "nothing";
    UpdatePanel1.Update();
    }

我的项目失败了:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.Internals.dll

Additional information: The Update method can only be called on UpdatePanel with ID 'UpdatePanel1' before Render.

即使我设置ChildrenAsTriggers与否。错误消息对我来说不清楚,我不明白在处理我的事件后我应该怎么做才能处理更新?

添加:

aspx:

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <asp:ListView ID="ListView1" runat="server">
        </asp:ListView>
    </ContentTemplate>
</asp:UpdatePanel>
4

2 回答 2

1

我想你应该像这样改变你的标记

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    ....

您应该UpdateMode="Conditional"在标记本身中设置

于 2013-02-04T06:31:18.237 回答
0
protected void Button1_Click(object sender, EventArgs e) {
    discovery.FindAlreadyRegisteredServices();
    discovery.discoveryClient.FindCompleted += FoundEvent;
  // Try to call the update method after calling the custom even but in the click event of the button. Ensure you update the Trigger accordingly in the update panel
 **UpdatePanel1.Update();**
}

protected void FoundEvent(object sender, FindCompletedEventArgs e) {
    Label1.Text = (discovery.endpoints.Count > 0) ? discovery.endpoints[0].Address.ToString() : "nothing";
       }

尝试以更新模式为条件将 AsyncPostBackTrigger 添加到更新面板

尽管您正在明确地做同样的事情。

<Triggers>  
                <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />  
            </Triggers>  

只是为了检查是否有任何其他问题,您可以将更新面板的 updateMode 属性设置为“始终”

于 2013-02-04T06:30:25.130 回答