Ajax Update Panel -- Conditional Update Mode

The Text of the lable still updated even though we had commented the update method of the "UpdatePanel".
Because we made the mistake listed as the third one.
 

When partial-page rendering is enabled, a control can perform a postback that updates the whole page or an asynchronous postback that updates the content of one or more UpdatePanel controls. Whether a control causes an asynchronous postback and updates an UpdatePanel control depends on the following:

  • If the UpdateMode property of the UpdatePanel control is set to Always, the UpdatePanel control's content is updated on every postback that originates from the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls.

  • If the UpdateMode property is set to Conditional, the UpdatePanel control's content is updated in the following circumstances:

    • When you call the Update() method of the UpdatePanel control explicitly.

    • When the UpdatePanel control is nested inside another UpdatePanel control, and the parent panel is updated.

    • When a postback is caused by a control that is defined as a trigger by using the Triggers property of the UpdatePanel control. In this scenario, the control explicitly triggers an update of the panel content. The control can be either inside or outside the UpdatePanel control that the trigger is associated with.

    • When the ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers.

The combination of setting the ChildrenAsTriggers property to false and the UpdateMode property to Always is not allowed and will throw an exception.

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConditionalUpdatePanelExample.aspx.cs" Inherits="ConditionalUpdatePanelExample" %>

<!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>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<ajaxToolkit:ToolkitScriptManager ID="scriptManager1" runat="server" />

<div>

<asp:Panel ID="conditionalPanel" runat="server">

<asp:UpdatePanel ID="conditionalUpdatePanel" runat="server" UpdateMode="Conditional">

<ContentTemplate>

<p>

Conditional:

<strong><%= DateTime.Now.ToBinary() %></strong>

</p>

<asp:UpdatePanel ID="nestedUpdatePanel" runat="server" UpdateMode="Conditional"

ChildrenAsTriggers="true">

<ContentTemplate>

<p>

Nested Conditional:

<string><%= DateTime.Now.ToBinary() %></string>

<asp:Button ID="uxNestedConditionalButton" runat="server" Text="Nested Conditional" />

</p>

</ContentTemplate>

</asp:UpdatePanel>

</ContentTemplate>

</asp:UpdatePanel>

</asp:Panel>

</div>

<div>

<asp:Button ID="uxButton" runat="server" Text="Do some server side stuff"

OnClick="Button_Click" />

</div>

</form>

<a href="Default.aspx">Previous one</a>

</body>

</html>

 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class ConditionalUpdatePanelExample : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

this.scriptManager1.RegisterAsyncPostBackControl(this.uxButton);

}

protected void Button_Click(object sender, EventArgs e) {

this.conditionalUpdatePanel.Update();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值