Fancybox popup in ASP.Net web form


In this post, I am going to explain you how to use fancy box to open a portion of you page as modal or non-modal popup.
Lets get started

Step 1 – Required javascript files for this example.

You can download the JQuery and fancybox api’s using the provided hyperlinks.

                    <script src="jquery-1.8.3.js" type="text/javascript"></script>


                    <script src="jquery-ui.js" type="text/javascript"></script>

                    <script type="text/javascript" src= "jquery.fancybox-1.3.4.js"></script>
                    <link rel="stylesheet" href="jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
 

 Step 2 – HTML code for Popup window.

                    <div style="display:none">
            <div id="AddNew">
                    <table>
                                             <tr>
                                         <td>Title</td>
                                         <td><input type="text" id="txtTitle"/></td>
                                             </tr>
                             </table>
            </div>
        </div>

 

Step 3 – Add a button or link on page, when user click on this control, the “AddNew” html code will open in a popup window. In this example I am going to use the hyperlink.

<a href="#AddNew" id="inline" >UK Morning Checks & Issues - List</a>

 

Step 4 - JQuery code to open the Popup

<script lang="javascript" type="text/javascript">
    $(document).ready(function () {
        $("a#inline").fancybox({
            'hideOnContentClick'false,



            'autoScale'false,
            'autoDimensions'false,
            openEffect: 'none',
            closeEffect: 'none',
            width: 200,
            height: 200,
            'modal'false
        });
    });
</script>

 

Step 6 – You can make the popup window modal and non-modal my changing the property of modal.

 

Modal –

<script lang="javascript" type="text/javascript">
    $(document).ready(function () {
        $("a#inline").fancybox({
            'hideOnContentClick'false,
            'autoScale'false,
            'autoDimensions'false,
            openEffect: 'none',
            closeEffect: 'none',
            width: 200,
            height: 200,
            'modal'true
        });
    });
</script>

 

Non-Modal

<script lang="javascript" type="text/javascript">
    $(document).ready(function () {
        $("a#inline").fancybox({
            'hideOnContentClick'false,
            'autoScale'false,
            'autoDimensions'false,
            openEffect: 'none',
            closeEffect: 'none',
            width: 200,
            height: 200,
            'modal'false
        });
    });
</script>


Step 5- Final outcome



Comments

Popular posts from this blog

SSIS Merge Join - Both inputs of the transformation must contain at least one sorted column, and those columns must have matching metadata SSIS

jsGrid

Add Item to SharePoint List with attachment using client object model