首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更新面板中的更新面板

更新面板中的更新面板
EN

Stack Overflow用户
提问于 2013-05-27 10:10:07
回答 2查看 10K关注 0票数 1

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

但是,我有一个timer对象,我只希望刷新updatepanel2。但是,我的整个页面都会刷新,而不仅仅是updatepanel2。

由于我不希望刷新母版页中的整个内容,我到底应该如何编写代码,使其只刷新updatepanel2而不刷新Updatepanel1。

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-27 13:39:22

MasterPage

代码语言:javascript
复制
<%@ 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>

ASPX页面

代码语言:javascript
复制
<%@ 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>

ASPX页面的代码隐藏

代码语言:javascript
复制
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();
        }
    }
}

备注:

在updatePanel2

  • Add AsynhronousTrigger inside UpadatePanel2中将两个更新面板的更新模式设置为"Conditional"

  • Add time

  • ,并将控件id设置为timer和tick eventas EventName.

  • Add
  1. AsynhronousTrigger in UpadatePanel2 timer_tick,请参见。

重要之处在于,您必须对服务器进行异步调用,以便仅更新页面的特定部分,并将updatepane的更新模式设置为有条件的,您还必须设置一些条件,以便在触发器中更新特定部分

希望这能对你有所帮助

感谢您继续编码......!:)

票数 2
EN

Stack Overflow用户

发布于 2013-05-27 11:22:58

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

或者,更好的做法是去掉UpdatePanels,使用JQuery或Microsoft Ajax来更新内容。它有较少的困难副作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16765519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档