[英]Updatepanel within an Update panel
我目前在“更新”面板中有一個更新面板。 例如,我有一個母版頁,母版頁中的所有內容都在一個updatepanel中,我將其命名為updatepanel1。 使用主頁面的aspx頁面中的較小更新面板稱為updatepanel2。
但是,我有一個計時器對象,只希望刷新updatepanel2。 但是,我的整個頁面都會刷新,而不僅僅是updatepanel2。
我應該如何編碼,以便僅刷新updatepanel2而不刷新Updatepanel1,因為我不希望刷新母版頁中的全部內容。
編輯:似乎不刷新的原因是因為我在頁面中留下了刷新HTML元標記,卻忘記了將其刪除。
母版
<%@ 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頁面
<%@ 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頁面的代碼隱藏
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中添加時間控件
在UpadatePanel2內添加AsynhronousTrigger並將控件ID設置為timer並在eventName上打上eventEvent。
將代碼添加到timer_tick evert中的代碼后面,請參閱。
重要的一點是,您必須對服務器進行異步調用,並且只將updatepane的頁面集更新模式的特定部分更新為Conditional,並且必須設置一些條件以在觸發器中更新該特定部分
希望這可以幫到你
謝謝你繼續編碼.........! :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.