Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新面板中的Updatepanel_C#_Asp.net_Asp.net Ajax_Updatepanel - Fatal编程技术网

C# 更新面板中的Updatepanel

C# 更新面板中的Updatepanel,c#,asp.net,asp.net-ajax,updatepanel,C#,Asp.net,Asp.net Ajax,Updatepanel,我目前在更新面板中有一个更新面板。例如,我有一个母版页,母版页中的所有内容都在一个updatepanel中,我将其命名为updatepanel1。使用母版页的aspx页面中较小的更新面板称为updatepanel2 然而,我有一个计时器对象,我只希望updatepanel2被刷新。但是,我的整个页面将刷新,而不仅仅是updatepanel2 由于我不希望刷新母版页中的全部内容,因此我应该如何编写代码,以便只刷新updatepanel2而不刷新Updatepanel1 编辑:它不刷新的原因似乎是因

我目前在更新面板中有一个更新面板。例如,我有一个母版页,母版页中的所有内容都在一个updatepanel中,我将其命名为updatepanel1。使用母版页的aspx页面中较小的更新面板称为updatepanel2

然而,我有一个计时器对象,我只希望updatepanel2被刷新。但是,我的整个页面将刷新,而不仅仅是updatepanel2

由于我不希望刷新母版页中的全部内容,因此我应该如何编写代码,以便只刷新updatepanel2而不刷新Updatepanel1

编辑:它不刷新的原因似乎是因为我在页面中留下了一个刷新HTML元标记,而忘记删除它。

说明了导致UpdatePanel更新的不同情况。我强烈建议您将更新面板的使用限制为只使用需要它的控件,而不是将整个页面包装在其中

或者,更好的是,消除UpdatePanel,使用JQuery或MicrosoftAjax更新内容。它有较少的困难的副作用。

母版页

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>

<!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>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>             
            <asp:UpdatePanel ID="UpdatePanel1" runat="server"  UpdateMode="Conditional">
            <ContentTemplate> <asp:Label  Id="lblmaster" runat="server" Text="Label"></asp:Label>
               <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder>
            </ContentTemplate>               
          </asp:UpdatePanel>     
    </div>
    </form>
</body>
</html>
注:

  • 将两个更新面板的更新模式设置为“有条件”

  • 在updatePanel2中添加时间控件

  • 在UpadatePanel2中添加AsynhronousTrigger,并将控件id设置为timer,并勾选eventas EventName

  • 在计时器中添加您的代码,在代码隐藏中勾选evert,然后查看

  • 重要的一点是,在这里您必须对服务器进行异步调用,并且为了只更新页面的特定部分,请将updatepane的更新模式设置为Conditional,并且您必须为更新触发器中的特定部分设置一些条件

    希望这能对你有所帮助


    谢谢你继续编码………!:)

    这两者的
    UpdateMode
    是什么?你能提供你的代码吗?
    <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Label ID="labelform" runat="server" Text="Label"></asp:Label>
              <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="10">
        </asp:Timer>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger  ControlID="Timer1" EventName="Tick"/>
        </Triggers>
    
        </asp:UpdatePanel>
    
    </asp:Content>
    
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication1
    {
        public partial class WebForm2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Timer1_Tick(object sender, EventArgs e)
            {
                labelform.Text = DateTime.Now.ToString();
             //  UpdatePanel1.Update();
                Label lblmaster = this.Master.FindControl("lblmaster") as Label;
                lblmaster.Text = DateTime.Now.ToString();
            }
        }
    }