AsyncPostBackTrigger disables buttons
I've a simple UpdatePanel and a button outside of it. I've introduced the button as an AsyncPostBackTrigger in the UpdatePanel. UpdatePanel itself works fine but the button does not. Whenever the button is clicked, its click handler does not run just like the butt开发者_运维问答on is not clicked at all!
Why the button is not working and how can it be fixed?
UPDATE: here is the markup:
<asp:UpdatePanel ID="upGridView" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="grdList" SkinID="SimpleGridView" DataKeyNames="Key" runat="server"
AllowPaging="True" PageSize="15" AutoGenerateColumns="False" Caption="<%$ Resources: CommonResources, grdListCaption %>"
EmptyDataText="<%$ Resources: CommonResources, grdListEmptyDataText %>" OnRowEditing="grdList_RowEditing"
OnPageIndexChanging="grdList_PageIndexChanging" OnRowCreated="grdList_RowCreated">
<Columns>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnDelete" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnNew" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnForward" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnDelete" runat="server" SkinID="Button" Text="<%$ Resources: CommonResources, btnDelete %>"
OnClick="btnDelete_Click" />
<asp:Button ID="btnNew" runat="server" SkinID="Button" Text="<%$ Resources: CommonResources, btnNew %>"
OnClick="btnNew_Click" />
<asp:Button ID="btnForward" runat="server" SkinID="Button" meta:resourcekey="btnForward"
OnClick="btnForward_Click" />
as its clear your Page (Module) does someting in Page_Load event and this event prevent potbacking your button.
I mean You try to post back, and Page_Load event run again and everything appear as the first time,
I had this problemt and resolveit by putting a
if(!IsPostBack)
DoSomething();
<asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers="False" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<form id="form1" runat="server" defaultbutton="btnSearch">
<div>
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true"
runat="server">
</asp:ScriptManager>
<script language="javascript" type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var postBackElement;
function InitializeRequest(sender, args)
{
if (prm.get_isInAsyncPostBack())
args.set_cancel(true);
postBackElement = args.get_postBackElement();
if (postBackElement.id == 'btnSearch')
$get('UpdateProgress1').style.display = 'block';
}
function EndRequest(sender, args)
{
if (postBackElement.id == 'btnSearch')
$get('UpdateProgress1').style.display = 'none';
}
</script>
</div>
<asp:GridView ID>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label2" runat="server" Text="Status"></asp:Label>
<asp:CheckBox ID="chkSelectAll" runat="server" onclick="javascript:HighlightRow(this);"
AutoPostBack="true" ToolTip="Click here to select all checkboxes"
OnCheckedChanged="chkSelectAll_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox ID="CheckBox1" onclick="javascript:HighlightRow(this);"
AutoPostBack="true" runat="server"
OnCheckedChanged="CheckBox1_CheckedChanged1" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server" ><ProgressTemplate>
<asp:Image ID="Imgwait" runat="server"
ImageUrl="~/Content/images/images/ApImages/001413_0.gif" />
<asp:Label ID="Lblwait" runat="server"
Text="Please wait while we process your request...." Font-Names="Tahoma"
Font-Size="10px" ForeColor="#990000"></asp:Label>
</ProgressTemplate>
</asp:UpdateProgress>
<div style="position: absolute;left:55%;top: 65%; vertical-align:middle; width:300px; text-align:center">
<asp:Panel ID="IMGDV" runat="server" Width="300px"
BackColor="#3D3327" Visible="False" BorderStyle="Outset">
<asp:Image ID="Image4" runat="server"
ImageUrl=" " Width="16px"
ToolTip="write your notes here for closure" />
<asp:Label ID="Label1" runat="server" CssClass="GridHeader"
Text="Please Provide note ."></asp:Label>
<table style="border-style: solid; border-width: thin; width: 100%; background-color: #D3CCC2;"><tr><td style=" text-align:center">
<asp:TextBox ID="TextBox2" Textmode="MultiLine" Height="80px" Width="250px"
CssClass="heading1" runat="server" ontextchanged="TextBox2_TextChanged"
BackColor="#D9D9CA" BorderColor="#3E1F00" BorderStyle="Inset"></asp:TextBox>
</td></tr>
</table>
<table style="border-style: outset; border-width: medium; width: 100%; background-color: #BDB2A4;">
<tr>
<td style=" text-align:left">
<asp:panel runat="server" ID="pnlsub" BackColor="#3D3327"
BorderStyle="Outset" Width="90%" ToolTip="Submit">
<asp:Button ID="Button1" runat="server" Text="Submit" CssClass="Button" BorderStyle="Solid" BorderColor="#3D3327" onclick="Button1_Click"/>
</asp:panel>
</td>
<td style=" text-align:left">
<asp:panel runat="server" ID="pnlcan" BackColor="#3D3327"
BorderStyle="Outset" Width="90%" ToolTip="Cancel">
<asp:Button ID="Button2" runat="server" Text="Cancel" CssClass="Button" BorderStyle="Solid" BorderColor="#3D3327" onclick="Button2_Click"/>
</td>
</tr>
</table>
</asp:Panel >
</div>
Code behind
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
IMGDV.Visible = true;
}
On checkbox checkchange event want to display pannel control but it is not dispalying pannel control help...
精彩评论