我刚接触ajax,打算用updatepanel,现在做了一个例子,始终不能局新刷新,请问一下有什么地方不对?原理:页面上放一个updatepanel控件,里面放一个label显示时间,外面再放一个label也显示时间,
如果能实现局部刷新,两个时间就不一样。前台代码:
<form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                <br />
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>后台:
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Label1.Text = DateTime.Now.ToString();
        this.Label2.Text = DateTime.Now.ToString();
        this.ScriptManager1.RegisterAsyncPostBackControl(this.Button1);
    }    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Label2.Text = DateTime.Now.ToString();
        this.UpdatePanel1.Update();
    }
}无论怎样都不能实现局部刷新,都是整页刷新,请问问题出在什么地方,始终找不到原因,这方面的helloworld也少。

解决方案 »

  1.   

    参考视频:http://download.microsoft.com/download/a/f/8/af881ab1-efd5-4b9a-ab40-2b8a4168119d/WinAudio-HDI-01-Get_Started_with_ASPNET_AJAX.wma
      

  2.   

    Button1_Click时间里写
    this.Label2.Text = DateTime.Now.ToString();就好.
      

  3.   

    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
            </asp:ScriptManager> 
    把这个放在Form后面看看。
    <form id="form1" runat="server"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server"> 
            </asp:ScriptManager> 
            <asp:Label ID="Label1" runat="server" Text="Label"> </asp:Label> <br />        
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
                <ContentTemplate> 
                    <asp:Label ID="Label2" runat="server" Text="Label"> </asp:Label> 
                    <br /> 
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> 
                </ContentTemplate> 
            </asp:UpdatePanel> 
        </form> 后台: 
    public partial class _Default : System.Web.UI.Page 

        protected void Page_Load(object sender, EventArgs e) 
        { 
            this.Label1.Text = DateTime.Now.ToString(); 
            this.Label2.Text = DateTime.Now.ToString(); 
            this.ScriptManager1.RegisterAsyncPostBackControl(this.Button1); 
        }     protected void Button1_Click(object sender, EventArgs e) 
        { 
            this.Label2.Text = DateTime.Now.ToString();             }