Update Page on Template button click from gridview within Modal Popup Extender

Posted on 2009-12-19
Last Modified: 2012-05-08
I have a Gridview within a Panel which is associated as the PopupControlID for AJAX Modalpopup extender.
When a button outside the panel is clicked, the popup is launched successfully displaying the gridview with the datarows and template command button, however when the command button is clicked, the gridview rowcommand for the button is not being fired therefore Page updates not being done.

Code EXTRACT Example below
    <asp:Button ID="btnLaunchPopup" runat="server" Text="Display"/>
    <cc1:ModalPopupExtender ID="ModalPopupExtender1"
<asp:Panel ID="pnlWorkArea" runat="server">
<asp:GridView ID="grdWithinPanel" DataKeyNames="rowvalue" />
                        <asp:BoundField DataField ="rowvalue" HeaderText="rowheader"  />
                            <asp:Button ID="BtnGetCommand" runat="server" CommandName="FireMyCommand" CommandArgument="<%# Container.DataItemIndex %>" Text="Go"/>
Question by:angelrbrown
    LVL 18

    Expert Comment


    I replicated your code on my devbox and apart from some minor errors:

    - no runat attribute specified for the GridView
    - some formatting issues for xhtml

    For me it works, it does indeed fire off the row command? I suspect that if it does not fire off the command it must be related to errors in code outside of the scope you have posted here because I suspect the missing runat attribute is just a typo here?


    Accepted Solution

    The runat="server" was accidentally removed in original post. I was building the code as a sample of what I have and mistakenly took it our however I found a solution to the problem by using an update panel for pnlWorkArea and within the grid added a asynchronicousPostBackTrigger on my button.

        <asp:UpdatePanel ID="PnlUpdateWorkArea" runat="server">  
                <asp:Panel ID="PnlWorkArea" runat="server" style="background-color:#FFFFFF;
            <asp:GridView ID="grdWithinPanel" DataKeyNames="rowvalue"
                AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333"
                GridLines="None"  ShowHeader="false" Width="100%">
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <asp:BoundField DataField ="rowvaluer" HeaderText="rowheader"  />
                        <asp:UpdatePanel UpdateMode="Always" ID="UpdatePanelforpostbackwithinGrid" runat="server">
                                <asp:Button ID="BtnGetCommand" runat="server" Text="Go" CommandArgument='<%# Bind("rowvaluer") %>' CommandName="FireMyCommand" EnableViewState="True" OnClientClick="HideModalPopup();" />
                                    <asp:AsyncPostBackTrigger ControlID="BtnGetCommand" EventName="Click" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now