简体   繁体   中英

OnClick Event Not Firing Inside LinkButton C#

I have a LinkButton that is wired up to an OnClick event and an href that fires a pop up modal.

My problem is that the modal window is popping up as expected, but the OnClick is not firing, it is not even hitting a break point inside the event.

I will post code below :

<asp:LinkButton href="#viewemydevices" data-toggle="modal" ID="ViewMyDevices" runat="server" OnClick="btnViewMyDevices_Click"></asp:LinkButton>

<div class="modal fade" id="viewemydevices" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4>This is a section</h4>
                </div>
                <div class="modal-body">
                    <table id="MyDevicesTable" class="table tbody" runat="server" visible="false">
                        <tbody>
                            <tr>
                                <td>
                                    <asp:DataGrid ID="MyDevicesGrid" runat="server" CssClass="table table-striped tbody" Visible="false"
                                        AutoGenerateColumns="True"
                                        ForeColor="black"
                                        HeaderStyle-Font-Bold="true"
                                        HeaderStyle-ForeColor="black"
                                        GridLines="None"
                                        EnableViewState="false"
                                        AllowSorting="True"/>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <a class="btn btn-primary" data-dismiss="modal">Close</a>
                </div>

            </div>
        </div>
    </div>



protected void protected void btnViewMyDevices_Click(object sender, EventArgs e)
{
     //logic goes here
}

UPDATE

<asp:LinkButton ID="ViewDevices" runat="server" OnClick="btnViewMyDevices_Click"></asp:LinkButton>

This updated code fires the on click event, but does not fire the modal...

The end product that is needed is when the link button is clicked it will display the modal and run the click event. The event a query that fills a datagrid in the body of the modal with the result set.

You are missing target of modal. Usually

data-toggle="modal" 

used in pare with

data-target="#viewemydevices"

for greater details please read this

EDIT: this functionality can be achieved by replacing your linkbutton with a regular html button which will display the modal and after that will make an AJAX call to your server-side function. Please see this article for details on placing AJAX call

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM