【问题标题】:How to call a callback function in a fancybox div using c# and code-behind?如何使用c#和代码隐藏在fancybox div中调用回调函数?
【发布时间】:2016-02-03 17:02:59
【问题描述】:

我在我的网页中添加了 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
}

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

【问题讨论】:

  • 您能否提供有关您的编码堆栈的更多详细信息?

标签: c# jquery callback fancybox code-behind


【解决方案1】:

您可能需要将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>

【讨论】:

  • 请看我的问题。我已经添加了代码,但它仍然无法正常工作。最好的问候。
  • 当你把它从花哨的盒子里拿出来时,它还能工作吗?
  • 我检查的不是很好,但是链接好像和你的问题差不多:stackoverflow.com/questions/2686362/…
  • 我在发布我的问题之前看到了这个链接,但是链接中的代码是针对以前版本的 Fancybox,所以我没有这个代码,如我的版本中的帖子所示( v.2.1.5)
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2014-06-13
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多