C# 更新面板中的Updatepanel
我目前在更新面板中有一个更新面板。例如,我有一个母版页,母版页中的所有内容都在一个updatepanel中,我将其命名为updatepanel1。使用母版页的aspx页面中较小的更新面板称为updatepanel2 然而,我有一个计时器对象,我只希望updatepanel2被刷新。但是,我的整个页面将刷新,而不仅仅是updatepanel2 由于我不希望刷新母版页中的全部内容,因此我应该如何编写代码,以便只刷新updatepanel2而不刷新Updatepanel1 编辑:它不刷新的原因似乎是因为我在页面中留下了一个刷新HTML元标记,而忘记删除它。说明了导致UpdatePanel更新的不同情况。我强烈建议您将更新面板的使用限制为只使用需要它的控件,而不是将整个页面包装在其中 或者,更好的是,消除UpdatePanel,使用JQuery或MicrosoftAjax更新内容。它有较少的困难的副作用。母版页C# 更新面板中的Updatepanel,c#,asp.net,asp.net-ajax,updatepanel,C#,Asp.net,Asp.net Ajax,Updatepanel,我目前在更新面板中有一个更新面板。例如,我有一个母版页,母版页中的所有内容都在一个updatepanel中,我将其命名为updatepanel1。使用母版页的aspx页面中较小的更新面板称为updatepanel2 然而,我有一个计时器对象,我只希望updatepanel2被刷新。但是,我的整个页面将刷新,而不仅仅是updatepanel2 由于我不希望刷新母版页中的全部内容,因此我应该如何编写代码,以便只刷新updatepanel2而不刷新Updatepanel1 编辑:它不刷新的原因似乎是因
<%@ 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>
注:
谢谢你继续编码………!:) 这两者的
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();
}
}
}