webform:
我以前在一段任务代码中加入了UpdatePanel2.Update();
执行是正常的。可以当我把这段代码放到线程中执行时却出现
[
  只能在 Render 之前在 ID 为“UpdatePanel2”的 UpdatePanel 上调用 Update 方法。
]
UpdatePanel设置如下
 <asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="False" 
                    UpdateMode="Conditional">
请问该如何解决?

解决方案 »

  1.   

    <asp:UpdatePanel ID="up2" runat="server" UpdateMode="conditional">
        <ContentTemplate>
       
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnShowTime" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
      

  2.   

    你的UpdatePanel2.Update()是放在哪一个方法里面的?是不是override了asp.net的页面事件并且该事件在Render之后?
      

  3.   

    前台:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="text1.aspx.cs" Inherits="main_text1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
          <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
        
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
            <br />
              <asp:UpdatePanel ID="UpdatePanel1" runat="server" 
                        UpdateMode="Conditional">
                         <ContentTemplate>
                         
                                   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                         
                                   </ContentTemplate>
                         <Triggers>
                             <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                         </Triggers>
                    </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>
    后台:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class main_text1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(loading));
            thread.Start();
           
        }    private void loading()
        {
            Label1.Text = "123123123";
            UpdatePanel1.Update();//错误提示:只能在 Render 之前在 ID 为“UpdatePanel1”的 UpdatePanel 上调用 Update 方法。
        }}
      

  4.   

    用线程异步调用UpadtePanel.Upadte()方法是不行的。
    如果想要使用线程操作页面控件,需要使用委托。