如何使用 c# 和代码隐藏在花哨的盒子 div 中调用回调函数



我在我的网页中添加了fancybox v.2.1.5,如下所示:

<script type="text/javascript" src="http://localhost/fancybox/jquery.mousewheel-3.0.6.pack.js"></script>
<script type="text/javascript" src="http://localhost/fancybox/jquery.fancybox.js?v=2.1.5"></script>
<link rel="stylesheet" type="text/css" href="http://localhost/fancybox/jquery.fancybox.css?v=2.1.5" media="screen" />
<link rel="stylesheet" type="text/css" href="http://localhost/fancybox/helpers/jquery.fancybox-buttons.css?v=1.0.5" />
<script type="text/javascript" src="http://localhost/fancybox/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
<link rel="stylesheet" type="text/css" href="http://localhost/fancybox/helpers/jquery.fancybox-thumbs.css?v=1.0.7" />
<script type="text/javascript" src="http://localhost/fancybox/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>
<script type="text/javascript" src="http://localhost/fancybox/helpers/jquery.fancybox-media.js?v=1.0.6"></script>

这是我的 html 代码:

<form id="aspnetForm" runat="server">
    <a href="#fancyBoxDiv" class="fancybox" />//When the anchor is clicked, shows fancyBoxDiv
    <div id="fancyBoxDiv">//This div is shown in fancybox
        <asp:Button ID="btn" runat="server" OnClick="btn_Click" />
    </div>
</form>

这是我的 c# 代码隐藏:

protected void btn_Click(object sender, EventArgs e)
{
    //This function is never called
}

我在一个花哨的盒子div 上有一个 c# 按钮,但是当我按下这个按钮时,代码隐藏中的回调函数没有被调用。我做错了什么?我必须改变什么?

您可能需要

asp:Button元素放在form标签中,如下所示:

<form id="form1" runat="server">
    <a href="#fancyBoxDiv" class="fancybox" />//When the anchor is clicked, shows fancyBoxDiv
    <div id="fancyBoxDiv">//This div is shown in fancybox
        <asp:Button ID="btn" runat="server" OnClick="btn_Click" />
    </div>
</form>

如果你认为你的html结构是正确的,那么你可以在firebug中检查你在客户端是否得到任何异常。或者第二个选项是检查您是否能够使用 OnClientClick 调用客户端函数。如果是这样,则调用客户端函数并使用 _doPostBack

最新更新