简体   繁体   中英

How to call a callback function in a fancybox div using c# and code-behind?

I have added fancybox v.2.1.5 in my webpage just like follows:

<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>

This is my html code:

<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>

This is my c# code-behind:

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

And I have one c# button on one fancybox div, but when I press this button, the callback function in codebehind is not called. What I'm doiing wrong? What I have to change?

You may need to put your asp:Button element inside a form tag like below:

<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>

If you think your html structure is proper then you can check if you're getting any exception on client side in firebug. Or second option will be to check if you're able to call a client side function by using OnClientClick . If so then call the client side function and use _doPostBack .

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