Most of the posts of this nature are old and seem to be resolvable now that there is a ChildrenAsTriggers attribute. I only see this in FireFox 2.0 not in IE7. My panel is defined:
<asp:UpdatePanel ID="bodyUpdatePanel" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSave" />
</Triggers>
<ContentTemplate>
<table>
<tr>
<td>
<asp:button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save Changes" />
<asp:button ID="btnCancel" runat="server" onclick="btnCancel_Click" Text="Cancel" CausesValidation="false"/>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
The problem is that the updatepanel is firing an update whether I click either button when I thought it should only fire when I click the button listed in the triggers attribute. Am I doing something wrong?
I tried this in both IE 7.0 and FireFox 2.0 and could not recreate the issue you are having.
I used the following:
<asp:UpdatePanelID="bodyUpdatePanel"runat="server"UpdateMode="conditional"ChildrenAsTriggers="false"><Triggers>
<asp:AsyncPostBackTriggerControlID="btnSave"/>
</Triggers>
<ContentTemplate>
<table>
<tr>
<td>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<asp:buttonID="btnSave"runat="server"onclick="btnSave_Click"Text="Save Changes"/>
<asp:buttonID="btnCancel"runat="server"onclick="btnCancel_Click"Text="Cancel"CausesValidation="false"/>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
On the code behind I just crufted this together:
protectedvoid Page_Load(object sender,EventArgs e)
{
Label1.Text =DateTime.Now.ToString();
}
protectedvoid btnSave_Click(object sender,EventArgs e)
{
}
protectedvoid btnCancel_Click(object sender,EventArgs e)
{
}
So all it should do is update the Label with the current time when I click on the btnSave button and not on the btnCancel button. I get the expected behaviour in both browsers.
Cheers,
Al
Thanks for your help. Because of your verification, I had to look elsewhere for the problem. I now see that the problem is not that the UpdatePanel fires when the non-triggered button is clicked. Instead the problem is that the PageRequestManager does a complete cycle for both the trigger and non trigger button. If I make the non trigger button abort the postback, the cycle still completes. I have simplified my example as much as I can but I am using a master page. If you click either button the PageRequestManager.BeginRequest event fires even though one button explicitly calls the abortPostback function.
Master page:
<%@. Master
Language="C#"
AutoEventWireup="true"
CodeFile="test.master.cs"
Inherits="web.test"
%
<!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">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<link href="http://links.10026.com/?link=assets/wdc/styles/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="modalBackground" class="modalHidden"></div>
<div id="progressBackground" class="modalHidden"></div>
<div id="progressWindow" class="modalHidden">
<table>
<tr align="center">
<td><span id="progressMessage" class="formLabelLeft">message</span></td>
</tr>
</table>
</div>
<asp:ContentPlaceHolder ID="cphMainContent" runat="server" />
</form>
</body>
</html>
Master page codebehind:
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;
namespace web
{
public partial class test : MasterPage
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
}
}
Test page:
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" MasterPageFile="~/test.master" %
<asp:Content ID="cphBody" runat="server" ContentPlaceHolderID="cphMainContent">
<asp:UpdatePanel ID="bodyUpdatePanel" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSave" />
</Triggers>
<ContentTemplate>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save Changes" />
<asp:button ID="btnCancel" runat="server" Text="Cancel" OnClientClick="Sys.WebForms.PageRequestManager.getInstance().abortPostBack();" CausesValidation="false"/>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<script language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(startProgress);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endProgress);
function startProgress()
{
document.getElementById('progressBackground').className = 'modalBackground';
document.getElementById('progressWindow').className = 'modalPopup';
document.getElementById('progressMessage').innerHTML = 'Please wait...';
for (var i=0;i<1250000;i++);
}
function endProgress(sender, args)
{
document.getElementById('progressBackground').className = 'modalHidden';
document.getElementById('progressWindow').className = 'modalHidden';
}
</script>
</asp:Content>
Test page codebehind:
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 test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Label1.Text = null;
}
}
No comments:
Post a Comment