Showing posts with label Sticky Footer. Show all posts
Showing posts with label Sticky Footer. Show all posts

Thursday, 21 April 2016

How to create sticky footer with asp.net master page?

Introduction 

Now i am going to explain how to create sticky footer with asp.net master page in simple manner.
 
Step 1
Add new visual studio project and add the necessary files like shown blow.
 
Step 2
Now open your Master Page and add this script within the head tag. 
  1. <head> 
  2. <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>  
  3.    <script type="text/javascript">  
  4.        $(window).bind("load"function () {  
  5.            var footer = $("#footer");  
  6.            var pos = footer.position();  
  7.            var height = $(window).height();  
  8.            height = height - pos.top;  
  9.            height = height - footer.height();  
  10.            if (height > 0) {  
  11.                footer.css({  
  12.                    'margin-top': height + 'px'  
  13.                });  
  14.            }  
  15.        });  
  16. </script>  
  17. </head>
 Step 3
Then write the following div within your form tag:
  1. <form id="form1" runat="server">  
  2.      
  3.  <div>  
  4.   
  5.            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">  
  6.   
  7.            </asp:ContentPlaceHolder>  
  8.   
  9.                      <div id="footer">  
  10.                      Your Footer Content  
  11.                       </div>  
  12.   
  13.  </div>  
  14.  </form>  
Step 4
Open your aspx page (for example default.aspx). Call your master page in your aspx page.
  1. <%@ Page Title="" Language="C#" MasterPageFile="Master.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="StickyFooter.default" %>  
Step 5
Remove all HTML elements from your default.aspx page. And add your content placeholder on your default.aspx page.
  1. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
  2.   
  3. Main Content (Header Content)  
  4.   
  5. </asp:Content>  
Now you can view your footer text at the bottom.