Hi All,
Hereby the updated post.
I faced the same problem this week. In the documentation I read about the RequiresUpdate property wich is a protected property on the UpdatePanel. Since it's a protected property I could'nt access it directly. That's why I created my own contol wich extends the update panel. I created an extra property "IsUpating", wich will indicate if an updatepanel is triggered for updating. The property will return true if a AscyncPostbackTrigger was raised or the Update method was called Directly. The downside of this solution is that the property is available not earlier then the OnLoadComplete Event.
Here´s the code for the extended component
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Web;
5 using System.Web.UI;
6
7 namespace UpdatePanelControlExtender
8 {
9 /// <summary>
10 /// Extends the Normal UpdatePanel so we can determine if the
11 /// UpdatePanel is in PartialRendering stage.
12 /// </summary>
13 public class ExtendedUpdatePanel : UpdatePanel
14 {
15
16 /// <summary>
17 /// Indicates that the UpdatePanel is updating
18 /// </summary>
19 public bool IsUpdating
20 {
21 get
22 {
23 return this.RequiresUpdate;
24 }
25 }
26 }
27
28 }
29 Below you find the Sample ASPX and the Code behind I used for testing. Basicly you have three buttons:
UpdateButton. The click event is added to the AsyncPostbackTriggerCollection, so ExtendedUpdatePanel2 will be updated
UpdateInCodeBehind. The Click event handler calls the UodateMethod of ExtendedUpdatePanel2, so ExtendedUpdatePanel2 will be updated
NoUpdateButton. This button will cause an update ExtendedUpdatePanel2
I have used an extra ExtendedUpdatepanel (ExtendedUpdatePanel1) to show is ExtendedUpdatePanel2 was updated.
Default.aspx file1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3 <%@ Register Assembly="UpdatePanelControlExtender" Namespace="UpdatePanelControlExtender"
4 TagPrefix="cc1" %>
5
6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
7 <html xmlns="http://www.w3.org/1999/xhtml">
8 <head runat="server">
9 <title>Untitled Page</title>
10 </head>
11 <body>
12 <form id="form1" runat="server">
13 <asp:ScriptManager ID="ScriptManager1" runat="server" />
14 <div>
15 <cc1:extendedupdatepanel id="ExtendedUpdatePanel1" runat="server" UpdateMode="Conditional"><ContentTemplate>
16 <asp:Label id="IsUpdatingLabel" runat="server" Text=""></asp:Label>
17 </ContentTemplate>
18 <Triggers>
19 <asp:AsyncPostBackTrigger ControlID="NoUpdateButton" EventName="Click" />
20 <asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click" />
21 <asp:AsyncPostBackTrigger ControlID="UpdateInCodeBehind" EventName="Click" />
22 </Triggers>
23 </cc1:extendedupdatepanel>
24 </div>
25 <cc1:extendedupdatepanel id="ExtendedUpdatePanel2" runat="server" UpdateMode="Conditional"><ContentTemplate>
26 <asp:Label id="TriggerUpdateTimeLabel" runat="server" Text=""></asp:Label>
27 </ContentTemplate>
28 <Triggers>
29 <asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click">
30 </asp:AsyncPostBackTrigger>
31 </Triggers>
32 </cc1:extendedupdatepanel>
33 <asp:Button ID="UpdateButton" runat="server" Text="Trigger Update Panel" />
34 <asp:Button ID="UpdateInCodeBehind" runat="server" Text="Call Update statement in Click event" OnClick="UpdateInCodeBehind_Click"/>
35 <asp:Button ID="NoUpdateButton" runat="server" Text="Do not trigger" />
36 </form>
37 </body>
38 </html>
39
Code Behind
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10
11 public partial class _Default : System.Web.UI.Page
12 {
13 protected void Page_Load(object sender, EventArgs e)
14 {
15 //this.TriggerUpdateTimeLabel.Text = DateTime.Now.ToLongTimeString();
16 }
17
18 protected override void OnLoadComplete(EventArgs e)
19 {
20 base.OnLoadComplete(e);
21 this.IsUpdatingLabel.Text = string.Format("Updatepanel updating = {0}", this.ExtendedUpdatePanel2.IsUpdating);
22
23 if (this.ExtendedUpdatePanel2.IsUpdating)
24 {
25 this.TriggerUpdateTimeLabel.Text = string.Format("update triggered at{0}",DateTime.Now.ToLongTimeString());
26 }
27 }
28
29 protected void UpdateInCodeBehind_Click(object sender, EventArgs e)
30 {
31 this.ExtendedUpdatePanel2.Update();
32 }
33 }