locked
Onclick event in Ajax Modal PopUp Extender. RRS feed

  • Question

  • User-1305858305 posted

    Hello

    In GridView which in UpdatePanel, I've a ImageButton that firing via OnRowcommand Event then displaying AjaxModalPopUp Extender.

    In my Modal PopUp I've Button with Onclick event. Modal PopUp displaying BUT

    OnClick Event doesnt firing.

    //gridview Image Button
    <asp:TemplateField HeaderText="Tel">
    <ItemTemplate>
     <asp:ImageButton runat="server" ID="ContactDetails" ImageUrl="~/Images/Phone-icon.png" CausesValidation="false"
    Width="20" Height="20" CommandName="WantToSeeContact" CommandArgument='<%# Bind("DiaID")%>' />
    <asp:HiddenField runat="server" ID="HiddenFieldUserID" Value='<%# Bind("UserID")%>' />
    </ItemTemplate>
    </asp:TemplateField>
    //modal
    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Panel2"
                                        PopupControlID="Panel2" >
                                    </ajaxToolkit:ModalPopupExtender>
                                    <asp:Panel ID="Panel2" runat="server" Width="500" Height="500"
                                        Style="background-color: #6f95f4; color: #000000; display: none">
                                        <div class="style1">
                                            <br />
                                            <br />
                                            <br />
                                            <br />
                                            <br />
                                            <table style="width: 90%; height: 71px;">
                                                <tr>
                                                    <td>Item Name</td>
                                                    <td>
                                                        <asp:Label ID="lblItemName" runat="server" Text="Label"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Price</td>
                                                    <td>
                                                        <asp:Label ID="lblPrice" runat="server" Text="Label"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">&nbsp;</td>
                                                </tr>
                                               
                                            </table>
                                            <br />
                                            <br />
                                            <asp:Button ID="btnAddToCart" runat="server" Text="Evet"
                                            onclick="btnAddToCart_Click"     />
                                            <br />
                                            <br />
    
                                            <asp:Button ID="btnClose" runat="server" Text="Close"
                                                Width="199px" />
                                        </div>
                                    </asp:Panel>
    
    

    Tuesday, March 24, 2015 8:22 PM

Answers

  • User61956409 posted

    Hi omerdemir,

    Thanks for your post.

    According to your description, I create the following sample to reproduce your problem, the code works fine on my side.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style>
            .bgcc {
                background-color: #ccc;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <div>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:TemplateField HeaderText="ID">
                            <ItemTemplate>
                                <asp:Label ID="lblid" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name">
                            <ItemTemplate>
                                <asp:Label ID="lblname" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Select">
                            <ItemTemplate>
                                <asp:LinkButton ID="btnpop" runat="server">Popup</asp:LinkButton>
                                <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnpop" PopupControlID="Panel1" BackgroundCssClass="bgcc"></asp:ModalPopupExtender>
                                <asp:Panel ID="Panel1" runat="server">
                                    <asp:Label ID="selectedname" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                                    <asp:Button ID="btngetname" runat="server" Text="GetName" CommandArgument='<%#Eval("Name") %>' OnClick="btngetname_Click" />
                                </asp:Panel>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <br />
                <asp:Label ID="lblselectedname" runat="server" Text=""></asp:Label>
            </div>
        </form>
    </body>
    </html> 
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID");
            dt.Columns.Add("Name");
    
            dt.Rows.Add("1", "Curry");
            dt.Rows.Add("2", "Sam");
            dt.Rows.Add("3", "Simon");
    
            GridView1.DataSource = dt;
            GridView1.DataBind();
    
        }
    }
    
    protected void btngetname_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        string name = btn.CommandArgument.ToString();
        lblselectedname.Text = name + " is selected";
    } 
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 26, 2015 2:49 AM