Article: Programmatically call FancyBox
Share/Save/Bookmark
Description: The following topic will show you how to call FancyBox programatically.

There are some basic things your page will need to have
  1. You'll need a ScriptManager on your page
  2. You'll need to add the proper links to your js files (JQuery & FancyBox)
To get started, you'll need to add the following <a> tag in your Mark-up.  This is link to your FancyBox page.

<a id="MyFancyBoxMessageCall"  
     href="../FancyBoxPages/MyMessagePage.aspx" 
     visible='false' ></a>



Next, you'll need to add the following script section to your page:
<script type="text/javascript">
    function sendMessage() {
        try {
            $(document).ready(function () 
{ $(
'#MyFancyBoxMessageCall).fancybox({ 'titleShow'false }); });             document.getElementById("MyFancyBoxMessageCall").click();         }         catch (ex) {  }     } </script>

From your code-behing (.cs or .vb), you'll need to add the following line of code: 

Note: you'll want to put this line where you want the code to generate the FancyBox Message (e.g. btnClick)

ScriptManager.RegisterStartupScript(this.Page, this.GetType(),    
"MyMessageScript""sendMessage();"true);