Hi KatieNgoc,
Place the JavaScript printpage function between the form tag and the Panel.
Check this example. Now please take its reference and correct your code.
HTML
Master Page
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
</head>
<body>
<form runat="server">
<script type="text/javascript">
function printpage() {
var getpanel = document.getElementById("<%= Panel1.ClientID %>");
var MainWindow = window.open('', '', 'height=500,width=800');
MainWindow.document.write('<html><head><title>Print Page</title><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />');
MainWindow.document.write('</head><body>');
MainWindow.document.write(getpanel.innerHTML);
MainWindow.document.write('</body></html>');
MainWindow.document.close();
setTimeout(function () {
MainWindow.print();
}, 500);
return false;
}
</script>
<asp:Panel ID="Panel1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
</Scripts>
</asp:ScriptManager>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar">
</span>
</button>
<a id="A1" class="navbar-brand" runat="server" href="~/">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a id="A2" runat="server" href="~/">Home</a></li>
<li><a id="A3" runat="server" href="~/About">About</a></li>
<li><a id="A4" runat="server" href="~/Contact">Contact</a></li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
<hr />
<footer>
<p>© <%: DateTime.Now.Year %> - My ASP.NET Application</p>
</footer>
</div>
</asp:Panel>
<asp:Button ID="Button1" runat="server" OnClientClick="return printpage();" Text="PRINT" />
</form>
</body>
</html>
Default Page
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">
ASP.NET is a free web framework for building great Web sites and Web applications
using HTML, CSS, and JavaScript.</p>
<p><a href="http://www.asp.net" class="btn btn-primary btn-lg">Learn more »</a></p>
</div>
<div class="row">
<div class="col-md-4">
<h2>Getting started</h2>
<p>
ASP.NET Web Forms lets you build dynamic websites using a familiar drag-and-drop,
event-driven model. A design surface and hundreds of controls and components let
you rapidly build sophisticated, powerful UI-driven sites with data access.
</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301948">Learn more »</a></p>
</div>
<div class="col-md-4">
<h2>Get more libraries</h2>
<p>
NuGet is a free Visual Studio extension that makes it easy to add, remove, and update
libraries and tools in Visual Studio projects.
</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301949">Learn more »</a></p>
</div>
<div class="col-md-4">
<h2>Web Hosting</h2>
<p>
You can easily find a web hosting company that offers the right mix of features
and price for your applications.
</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301950">Learn more »</a></p>
</div>
</div>
</asp:Content>
Screenshot
Print Preview