Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
2.50/5 (4 votes)
See more:
I am getting an error when i call the button id which is inside GridView Item template.

Error: "The TargetControlID of 'mpueResend' is not valid. A control with ID 'btnResend' could not be found."

Code:

C#
<asp:GridView ID="GridMultiD" runat="server" CellPadding="3" 
                        AlternatingRowStyle-BackColor="#EDF3F7" HeaderStyle-CssClass="gridbgheading" 
                        Width="100%" HeaderStyle-HorizontalAlign="Center" >
                        
                    
                    <Columns>
                        <asp:TemplateField HeaderText="Resend">
                            <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:Button ID="btnResend" runat="server" Text="Resend" CssClass="text ButtonInline"  />
                                </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                        
                    </asp:GridView>


C#
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:ModalPopupExtender ID="mpueResend" runat="server" TargetControlID="btnResend" PopupControlID="pnlPopupResend" 
        BackgroundCssClass="modalBackGround" DropShadow="true" CancelControlID="btnCancelR" >
    </asp:ModalPopupExtender>


Please let me know if there is any solution for this.

Thank You.
Posted

Added a dummy hidden field for ModalPopUp in aspx page and in code behind added ModalPopup.show().

C#
<asp:HiddenField ID="hfHidden" runat="server />
<asp:ModalPopupExtender ID="mpueResend" runat="server" TargetControlID="hfHidden" PopupControlID="pnlPopupResend" 
        BackgroundCssClass="modalBackGround" DropShadow="true" CancelControlID="btnCancelR" />

<asp:GridView ID="GridMultiD" runat="server" CellPadding="3" AlternatingRowStyle-BackColor="#EDF3F7" HeaderStyle-CssClass="gridbgheading" Width="100%" HeaderStyle-HorizontalAlign="Center" OnRowCommand="GridMultiD_RowCommand">  
    <Columns>
        <asp:TemplateField HeaderText="Resend">
            <ItemStyle HorizontalAlign="Center" />
            <ItemTemplate>
                 <asp:Button ID="btnResend" runat="server" Text="Resend" CssClass="text ButtonInline"  CommandName="ViewComments" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns> 
</asp:GridView>


C#
protected void GridMultiD_RowCommand(object sender, GridViewCommandEventArgs e)
{
    switch (e.CommandName) // check the incoming command name
    {
        case "ViewComments":
            mpueResend.Show();
            break;
    }        
}


Thank You
 
Share this answer
 
v3
if the modal is outside the grid then it wont recognize the button because it cant see it. My advice is to put the modal inside the grid and it will work perfectly !
 
Share this answer
 
Comments
Member 4581741 19-Jan-12 17:15pm    
I am only to put the modalpopup extender inside Itemtemplate.
If i do so it slows down the website by much as it tried to load the modal for each row of column being generated by gridview datasource.

What i want is that i need to add a button column inside the grid view and when that button is called need to open a popup with some values of that row.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900