如果我们添加"data-toggle =" modal",则不会触发LinkBut​​ton Click事件.data-target =“#modalEmployee"aspx文件中linkbutton的属性 [英] LinkButton Click event is not firing if we add "data-toggle="modal" data-target="#modalEmployee" property of linkbutton in aspx file

查看:206
本文介绍了如果我们添加"data-toggle =" modal",则不会触发LinkBut​​ton Click事件.data-target =“#modalEmployee"aspx文件中linkbutton的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分配了Bootstrap Modal的LinkBut​​ton:

I have a LinkButton that a Bootstrap Modal is assigned to it:

<asp:LinkButton runat="server" ID="btnEdit" data-toggle="modal" data-target="#modalEmployee">
    <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/addEmp.png" />&nbsp;Add
</asp:LinkButton>

模式已正确显示,但未触发Codebehind Click事件:

The modal is show up correctly but Codebehind Click Event is not fired:

Protected Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
        ScriptManager.RegisterClientScriptBlock(Me, Me.GetType, "Show", "<script type='text/javascript'> $('#modalEmployee').modal('show');</script>", True)
End Sub

推荐答案

使用以下代码:

<asp:LinkButton runat="server" ID="btnEdit">
   <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/Icons/add.png" />&nbsp;Add
</asp:LinkButton>

对于后面的代码,请使用:

And for the code behind, use:

Protected Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
    Dim id = SelectedRowID
    If id.HasValue Then

        Page.ClientScript.RegisterStartupScript(Me.GetType, "Show", "$(document).ready(function() {$('#modalAttorney').modal('show');});", True)

        EditRecord(id.Value)

    End If
End Sub

请记住,仅在文档准备好后才触发Javascript事件.我希望这会有所帮助.

Remember that Javascript events only fire after the document is ready. I hope this helps.

这篇关于如果我们添加"data-toggle =" modal",则不会触发LinkBut​​ton Click事件.data-target =“#modalEmployee"aspx文件中linkbutton的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆