简体   繁体   English

LinkBut​​ton C#内未触发OnClick事件

[英]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. 我有一个连接到OnClick事件的LinkButton和一个激发弹出模式的href。

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. 我的问题是模式窗口正在按预期方式弹出,但是OnClick不会触发,它甚至没有达到事件内部的断点。

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... 此更新的代码会触发on click事件,但不会触发模式...

The end product that is needed is when the link button is clicked it will display the modal and run the click event. 所需的最终产品是单击链接按钮时,它将显示模式并运行click事件。 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. 编辑:可以通过将您的linkbutton替换为一个常规的html按钮来实现此功能,该按钮将显示模式,之后将对您的服务器端函数进行AJAX调用。 Please see this article for details on placing AJAX call 请参阅本文 ,了解有关拨打AJAX电话的详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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