I have a bit of a strange problem and wondering if anyone can help.
I have an update panel that has a timer set as the AsyncPostBackTrigger. In this Update Panel I have a repeater and in the repeater I have a few buttons which have on click events.
The 开发者_StackOverflow社区on click of these buttons does not appear to fire until the timer has ticked. I have tried debugging and this is what seems to be happening, either way it takes ages for the button click to actually fire.
Does anyone know why this would be and what I can do about it?
My code is as follows:
Update Panel
<asp:UpdatePanel ID="CheckListUpdatePanel" runat="server">
<ContentTemplate>
<div><asp:Label ID="CannotBeLoadedLabel" runat="server" Visible="false"></asp:Label></div>
<table>
<asp:Repeater ID="ChecklistRepeater" runat="server">
<ItemTemplate>
<tr>
<td>
<%# Eval("Description")%>
</td>
<td>
<%# Eval("Priority")%>
</td>
<td>
<td>
<asp:Button ID="SetAsCompleteButton" CommandArgument='<%# Eval("EventChecklistId")%>'
runat="server" OnClick="SetAsCompleteButton_Click" Text="Close" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
Some of my code behind:
Protected Sub SetAsCompleteButton_Click(ByVal sender As Object, ByVal e As EventArgs)
timer1.Enabled = False
~~do complete code
timer1.Enabled = True
End Sub
Protected Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick
timer1.Enabled = False
LoadEventChecklist()
timer1.Enabled = True
End Sub
Thanks
Bex
<%# Eval("EventChecklistId")%>
This could be the reason. What is the value inside ? It could require full postback to evaluate.
You should use itemCommand event of the Repeater to capture the button click, something like
protected void ChecklistRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
e.CommandArgument // This will give the argument specified in the button
//Your Code
}
and you can get the event argument as e.CommandArgument inside this method to process accordingly.
It seems that something else was causing the button to appear as if it was not being fired until the timer click. So none of the other answers were a problem, although useful to know for future.. I am marking this as answer to close the question..
Feel free to delete
精彩评论