What would cause an asp Button not to fire after a partial update has occured?
<asp:UpdatePanel ID="upPan" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSave" ClientIDMode="Static" runat="Server" Text="Save" CausesValidation="false" />
</ContentTemplate>
</asp:UpdatePanel>
- The first time any button is fired inside the update panel the below routines fire in this order.
- After a postback has occured triggering the button again causes a postback, both
Load
andPreRenderComplete
events fire but the click event is skipped.
VB
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.PageLoad
//Runs everytime
End Sub
Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
//Doesn't fire after first postback.
End Sub
Protected Sub Page_PreRenderComplete(sender As Object, e As EventArgs) Handles Me.PreRenderComplete
//Runs everytime
End Sub
FAILED RESOLUTIONS
Suggestions to resolve this include:
ChildrenAsTriggers= "True"
This is already the default behaviour of UpdatePanel and offers no change.<asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
Again by default child controls of the panel cause an asynchronous postback and declaring triggers is redundant.
SUCCESSFUL RESOLUTION
If I simply change the asp:Button
into an asp:LinkButton
the issue is resolved.
SUMMARY
The postback is occuring but the click event is being missed when the sender is an asp:Button control.
Can anyone explain what would cause this behaviour?
Best Answer
First up, apologies my answer is in C#. It's also not much of an answer as I can't replicate your issue. The distinction between Buttons and LinkButtons is that a
Button
uses submit behaviour and aLinkButton
uses a javascript postback. You could try puttingUseSubmitBehavior="false"
on your Button, that'll make it work like aLinkButton
.Here's my complete test code. Being C# I had to make a few changes as it doesn't have
Handles
- which maybe a key to the issue as C# and VB handle events slightly differentlyCodeBehind:
Clicking the Button (or the LinkButton) works and updates the TextBox everytime: