English 中文(简体)
Triggering FancyBox from ASP. Net Codebehind
原标题:Triggering FancyBox from ASP.Net Codebehind

I want to use the JQuery FancyBox on an asp.net page but all the examples I have found show triggering a fancybox from anchor tag (< a >). I am not able to find an example where a fancybox is triggered from codebehind. To be more specific, I create a pdf file on the fly on a LinkButton click. After the file has been created, I want to show it using fancybox (I am using Jquery and FancyBox for the first time). Any examples showing how to do this will be much appreciated. Thanks.

问题回答

在你接通了这个网页(后台)之后,你想将一些文字注入你的网页。

你的网页应当有这样的内容。

<a href="#" id="hidden_link" style="display:none;"></a>
<script type="text/javascript">
    function LaunchFancyBox() { 
          $("#hidden_link").fancybox().trigger( click ); 
    } 
</script>

然后,你将用 but子点击手把一些文字放在网页底部。

因此,在你网页的底部,你会增加像你这样的东西。

<asp:Literal runat="server" ID="Literal1" />

接着,在你 but子的点击活动中,你会把你带在你身上。

Public Sub Button1_Click()
    Literal1.Text = "<script>$(document).ready(LaunchFancyBox());</script>"
End Sub

http://fancy Box.net/blog"rel=“nofollow noreferer”>blog 同时也有助于解释这一点,然而,他们总是在一页的负荷上重新启用,因此没有必要注入文字。 但是,由于你想在背后这样做,你需要做文字注射。

溶解。 对岩石的答复仅作一些细微的调整。 离开

<script language="javascript" type="text/javascript">
$(document).ready(function() {
    $("#hidden_link").fancybox({
         title          :  Test Document ,
         titleShow      : true,
         titlePosition  :  over ,
         titleFormat    :  formatTitle ,
         type           :  iframe ,
         width          :  98% ,
         height         :  98% ,
         hideOnOverlayClick : false,
         hideOnContentClick  : false,
         overlayOpacity : 0.7,
         enableEscapeButton  : false
    });
});
</script>

在主角,《刑法》如下:

protected void SomeButton_Click(object sender, EventArgs e)
{          
    hidden_link.Attributes["href"] = "some_file.pdf";
    Literal1.Text = "<script>jQuery(document).ready(function() {$("#hidden_link").trigger( click );});</script>";
}

• 提出正确方向的示意。

我正在使用协会。 净额与VB。 净额为代码

ASPX: 1) I have a hidden anchor with style as display:none and no Literal Add hidden anchor tag id="hidden_link" clientidmode="static" style="display:none;" class="fancybox fancybox.iframe"

在内容领域或标题方面:

 script type="text/javascript">
             $("#hidden_link").fancybox({
             // title :  Test Document ,`enter code here
             // titleShow : true,
             // titlePosition :  over ,
             // titleFormat :  formatTitle ,
             href: "SessioDocqReportPreview.aspx",
              width :  98% ,
              height :  98% ,
              hideOnOverlayClick : false,
              hideOnContentClick : false,
              overlayOpacity : 0.7,
              enableEscapeButton : false            
         }); 

     });
2) In the code behind button click event 
     Dim csMgr As ClientScriptManager = Me.ClientScript
     If Not csMgr.IsStartupScriptRegistered("OpenPopUp_Script") Then
       Dim sb As New StringBuilder()
       sb.AppendLine("$(document).ready(function() {")
       sb.AppendLine("$(""#hidden_link"").trigger( click );")
       sb.AppendLine("return false;")
       sb.AppendLine("});")
       hidden_link.Attributes("href") = "xyz.aspx"
       csMgr.RegisterStartupScript(Me.GetType(), "OpenPopUp_Script", sb.ToString(), True)
     End If
3) This way we can get rid of Literal control, if still want to use the set the sb.Tostring to the text of the literal control with script tags and ofcourse remove the StatupScript.
BTW my fancybox is from www.fancyapps.com and v2.0.




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签