I did a lot of searching and cannot figure this out.
I have a ModalPopupExtender pop-up that I want to display when the user clicks a link DoSomething. The pop-up has a dropdown control that I then want to populate on the fly when the user asks to open the dialogue. This needs to happen server side via the code behind. Currently I am trying to do it via an OnClick event on the link but as soon as the link is tied to the ModalPopupExtender the link OnClick code is not executed.
Code snippet:
<asp:LinkButton ID="lnkDoSomething" runat="server" onClick="lnkDoSomething_Click">Do Something</asp:LinkButton>
<asp:ModalPopupExtender ID="mpelnklnkDoSomething" runat="server" BackgroundCssClass="modalBackground"
DropShadow="true" PopupControlID="lnkDoSomething"
PopupDragHandleControlID="pnlDragHandlerForlnkDoSomething"
TargetControlID="lnklnkDoSomething"></asp:ModalPopupExtender>
The problem is as soon as I set the ModalPopupExtender to the link the OnClick code does not execute. This obviously is by design but it doesn't make sense to me (naive) as if the user clicks the link the OnClick code should be executed.
Any ideas why this is not supported and what the correct solution is?
Attach the ModalPopupExtender
to a dummy button and show the modal on the LinkButton
's OnClick
even from the code-behind:
Markup:
<asp:LinkButton ID="lnkDoSomething" runat="server" onClick="lnkDoSomething_Click">Do Something</asp:LinkButton>
<asp:Button id="dummyButton" runat="server" style="display:none;" />
<asp:ModalPopupExtender ID="mpelnklnkDoSomething" runat="server"
BackgroundCssClass="modalBackground" DropShadow="true" PopupControlID="controlToPopUpId"
PopupDragHandleControlID="pnlDragHandlerForlnkDoSomething"
TargetControlID="dummyButton"></asp:ModalPopupExtender>
Code-behind:
protected void lnkDoSomething_Click(Object sender, EventArgs e)
{
//do work
mpelnklnkDoSomething.Show();
}