I’m trying to show Modal Popup when a user clicks LinkButton in GridView.
I placed a break point for testing but it doesn’t seem to pass through ModalPopupExtender.Show() Event when i click the Linkbutton in the Gridview.
protected void lnkItemName_Click(object sender, EventArgs e)
{<---Break Point
ModalPopupExtender.Show();
}
<asp:GridView ID="grvItem" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSourceItem" onrowdatabound="grvItem_RowDataBound"
DataKeyNames="ID">
<Columns>
<asp:TemplateField >
<ItemStyle Font-Size="10" />
<HeaderTemplate>
ITEM
</HeaderTemplate>
<ItemStyle Wrap="True" />
<ItemTemplate>
<asp:LinkButton ID="lnkItemName" runat="server" Text='<%# Eval("NAME") %>' CssClass="h7" Width="100" OnClick="lnkItemName_Click"></asp:LinkButton>
<asp:Panel ID="pnlItem" runat="server" Style="display: none" Width="400px" Height="400px" BackColor="White">
<div style="float: right;">
<asp:LinkButton ID="lnkClose" runat="server">Close</asp:LinkButton>
</div>
<asp:TextBox ID="txt" runat="server">asdf</asp:TextBox>
</asp:Panel>
<asp:ModalPopupExtender ID="extPerson" runat="server" TargetControlID="lnkItemName"
PopupControlID="pnlItem" DropShadow="true" CancelControlID="lnkClose" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
“lnkItemName” is a TargetControlID for “extPerson”, so “lnkItemName_Click” doesn’t get called at all – it is instead handled by ModalPopupExtender and “pnlItem” is shown automagicaly. If you want to, you can remove the TargetControlID property, then the “lnkItemName_Click” will get called on the server, so you can show “pnlItem” manualy – BUT, you would first have to somehow find the right “extPerson” control (every row has one), cast it as ModalPopupExtender, and then call Show() on it.
Long story short, just simply remove OnClick event, its useles – if Modal Popup is not showing the way it is now, something else is wrong.