Reputation: 23
I have an Ajax ModalPopUpExtender
which works fine when launched by the target control, but what I want to do is launch it from a server side Button_Click
event in VB.
This is because I want to check some variables before launching the ModalPopUpExtender
.
I have tried the .show
method which works fine on an initial PageLoad
event when there is no post back, but the method won't work from an asp:button
's onclick
event or from a post back event.
I have given the ModalPopUpExtender
a dummy button to target as you can't run one without the TargetControlID
being set. The dummy control is visible.
As the .show
method works on a PageLoad
event I know the ModalPopUpExtender
is set up correctly, but what could be stopping it from running from a server-side event?
Here's my code:
<ajax:ModalPopupExtender
ID="mp1"
runat="server"
PopupControlID="Panel1"
TargetControlID="btnShowPopUp" CancelControlID="btnClose"
BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
Sub btnShow_Click(ByVal sender As Object, ByVal e As EventArgs)
if myVariable = 1 then
mp1.show
End if
End Sub
Upvotes: 0
Views: 1383
Reputation: 23
After searching on more permutations of my question I finally found the answer in an existing answer on the site. The target control has to be a hidden field object, not another button.
The full answer is at:
ASP.NET: ModalPopupExtender prevents button click event from firing
Upvotes: 1