.aspx//前台<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Drag.aspx.cs" Inherits="Default2" validateRequest="false"  %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head id="Head1" runat="server">
    <title>UpdateProgress Example</title>
    <style type="text/css">
    #UpdatePanel1, #UpdatePanel2, #UpdateProgress1 {
      border-right: gray 1px solid; border-top: gray 1px solid; 
      border-left: gray 1px solid; border-bottom: gray 1px solid;    
    }
    #UpdatePanel1, #UpdatePanel2 { 
      width:200px; height:200px; position: relative;
      float: left; margin-left: 10px; margin-top: 10px;
     }
     #UpdateProgress1 {
      width: 400px; background-color: #FFC080; 
      bottom: 0%; left: 0px; position: absolute;
     }
    </style>
     
</head>
<body>    <form id="form1" runat="server">
    <div>
    
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
   
    <asp:LinkButton ID="ButtonTrigger" runat="server" Text="Refresh Panel 1" OnClick="Button_Click" />    
    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <Triggers>
      <asp:AsyncPostBackTrigger ControlID="ButtonTrigger" />
    </Triggers>
    <ContentTemplate>
    <div>
    <%=DateTime.Now.ToString() %> <br />
    The trigger for this panel 
    causes the UpdateProgress to be displayed
    even though the UpdateProgress is associated
    with panel 2.     
    <br />
    </div>
    </ContentTemplate>
    
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
    <%=DateTime.Now.ToString() %> <br />
    <asp:Button ID="Button2" runat="server" Text="Refresh Panel" OnClick="Button_Click"/>    
    </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel2" >
    <ProgressTemplate>
      <asp:Image ID="loading" runat="server" 
            ImageUrl="~/SystemImages/loadingtiao.gif" />
      <input type="button" value="stop" onclick="AbortPostBack()" />
    </ProgressTemplate>
    </asp:UpdateProgress>
    </div>
    <script type="text/javascript">
    <!--
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);
    var postBackElement;
    function InitializeRequest(sender, args) {
       if (prm.get_isInAsyncPostBack())
       {
          args.set_cancel(true);
       }
       postBackElement = args.get_postBackElement();
       if (postBackElement.id == 'ButtonTrigger')
       {
         $get('UpdateProgress1').style.display = "block";
         $get('UpdatePanel1').style.display = "none";
       }
       if( postBackElement.id='Btuserlogin')
{
    $get('UpPruserlogin').style.display="block";
    $get('Upuserlogin').style.display="none";
}
    }
    function EndRequest (sender, args) {
       if (postBackElement.id == 'ButtonTrigger')
       {
         $get('UpdateProgress1').style.display = "none";
         $get('UpdatePanel1').style.display="block";    
       }
       if(postBackElement.id='Btuserlogin')
    {
        $get('UpPruserlogin').style.display="none";
        $get('Upuserlogin').style.display="block";
    }
    }
    function AbortPostBack() {
      if (prm.get_isInAsyncPostBack()) {
           prm.abortPostBack();
      }        
    }
    //-->
    </script>
<div class="daohang-left-bottom"></div>
<div class="daohang-right-bottom"></div>
<div id="daohang-zhong-bottom">
    <asp:UpdatePanel ID="Upuserlogin" runat="server" >
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="Btuserlogin" EventName="click" />
    </Triggers>
    <ContentTemplate>
        <asp:Label ID="Lbusername" runat="server" Text="用户名:"></asp:Label><asp:TextBox ID="Txtusername" runat="server"></asp:TextBox><asp:Label
            ID="Lbuserpsw" runat="server" Text="密码:"></asp:Label><asp:TextBox ID="Txtuserpsw"
            runat="server"></asp:TextBox>
    </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="UpPruserlogin" runat="server" AssociatedUpdatePanelID="Upuserlogin">
    <ProgressTemplate>
        <asp:Image ID="Imgloading" runat="server" ImageUrl="/SystemImages/loadingtiao.gif" />
    </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:Button ID="Btuserlogin" runat="server" Text="登陆" 
        onclick="Btuserlogin_Click" />
</div>
    
    </form>
</body>
</html>.cs//后台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;
using FilterRealProxy;public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
           
        }
    }    protected void Button_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
    }
    protected void Btuserlogin_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
    }
}上边的例子是通过msdn上边改的,我在一个界面实现多个按钮来更新自己的UpdatePanel,例如我点按钮1只更新 UpdatePanel1的更新,可是实际不是这样的他会更新第一个和第3个UpdatePanel 研究了好久不知道为什么呢?难道是bug 还是微软的ajax 框架化不让这么用?还有就是点击第二个按钮会激活所有UpdatePanel更新着使我很不解希望哪位高手能讲解下,在一个界面如何使用多个UpdatePanel UpdateProgress 来控制区域更新!

解决方案 »

  1.   

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
            </asp:ScriptManager>
    所有的UpdatePanel设置UpdateMode="Conditional":
     <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
           <ContentTemplate>                                       
               </ContentTemplate>
                 <Triggers>
               <asp:AsyncPostBackTrigger ControlID="" EventName="Click" />
               </Triggers>
      </asp:UpdatePanel>
    http://www.cnblogs.com/footleg/archive/2008/07/07/1237393.html
      

  2.   

    wuyq11  都改成Conditiona 也一样没用!如果不用UpdateProgress 编程就不会出现混乱刷新!
      

  3.   

    楼主,可能是你所有UpdatePanel的updateMode属性的值是Always(全刷新).
    如果是这个原因,updateMode的值改为Conditional(单命令刷新),然后使用Triggers分别绑定对应按钮ID和事件
    你可以看看类似帖子http://topic.csdn.net/u/20080409/19/f1b093dd-e078-49ec-92d9-2eac060d724d.html