ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Print Page having Master Page using JavaScript in ASP.Net<p>Hi&nbsp;KatieNgoc,</p> <p>Place the JavaScript printpage function between&nbsp;the form tag and the&nbsp;Panel.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <p><span style="text-decoration: underline;">Master Page</span></p> <pre class="brush: html">&lt;%@ Master Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;Site.master.cs&#34; Inherits=&#34;Site&#34; %&gt; &lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&gt; &lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;meta charset=&#34;utf-8&#34; /&gt; &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width, initial-scale=1.0&#34; /&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css&#34; /&gt; &lt;/head&gt; &lt;body&gt; &lt;form runat=&#34;server&#34;&gt; &lt;script type=&#34;text/javascript&#34;&gt; function printpage() { var getpanel = document.getElementById(&#34;&lt;%= Panel1.ClientID %&gt;&#34;); var MainWindow = window.open(&#39;&#39;, &#39;&#39;, &#39;height=500,width=800&#39;); MainWindow.document.write(&#39;&lt;html&gt;&lt;head&gt;&lt;title&gt;Print Page&lt;/title&gt;&lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css&#34; /&gt;&#39;); MainWindow.document.write(&#39;&lt;/head&gt;&lt;body&gt;&#39;); MainWindow.document.write(getpanel.innerHTML); MainWindow.document.write(&#39;&lt;/body&gt;&lt;/html&gt;&#39;); MainWindow.document.close(); setTimeout(function () { MainWindow.print(); }, 500); return false; } &lt;/script&gt; &lt;asp:Panel ID=&#34;Panel1&#34; runat=&#34;server&#34;&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34;&gt; &lt;Scripts&gt; &lt;/Scripts&gt; &lt;/asp:ScriptManager&gt; &lt;div class=&#34;navbar navbar-inverse navbar-fixed-top&#34;&gt; &lt;div class=&#34;container&#34;&gt; &lt;div class=&#34;navbar-header&#34;&gt; &lt;button type=&#34;button&#34; class=&#34;navbar-toggle&#34; data-toggle=&#34;collapse&#34; data-target=&#34;.navbar-collapse&#34;&gt; &lt;span class=&#34;icon-bar&#34;&gt;&lt;/span&gt;&lt;span class=&#34;icon-bar&#34;&gt;&lt;/span&gt;&lt;span class=&#34;icon-bar&#34;&gt; &lt;/span&gt; &lt;/button&gt; &lt;a id=&#34;A1&#34; class=&#34;navbar-brand&#34; runat=&#34;server&#34; href=&#34;~/&#34;&gt;Application name&lt;/a&gt; &lt;/div&gt; &lt;div class=&#34;navbar-collapse collapse&#34;&gt; &lt;ul class=&#34;nav navbar-nav&#34;&gt; &lt;li&gt;&lt;a id=&#34;A2&#34; runat=&#34;server&#34; href=&#34;~/&#34;&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id=&#34;A3&#34; runat=&#34;server&#34; href=&#34;~/About&#34;&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id=&#34;A4&#34; runat=&#34;server&#34; href=&#34;~/Contact&#34;&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;container body-content&#34;&gt; &lt;asp:ContentPlaceHolder ID=&#34;MainContent&#34; runat=&#34;server&#34;&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;hr /&gt; &lt;footer&gt; &lt;p&gt;&amp;copy; &lt;%: DateTime.Now.Year %&gt; - My ASP.NET Application&lt;/p&gt; &lt;/footer&gt; &lt;/div&gt; &lt;/asp:Panel&gt; &lt;asp:Button ID=&#34;Button1&#34; runat=&#34;server&#34; OnClientClick=&#34;return printpage();&#34; Text=&#34;PRINT&#34; /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><span style="text-decoration: underline;">Default Page</span></p> <pre class="brush: html">&lt;%@ Page Title=&#34;&#34; Language=&#34;C#&#34; MasterPageFile=&#34;~/Site.master&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;Default.aspx.cs&#34; Inherits=&#34;_Default&#34; %&gt; &lt;asp:Content ID=&#34;Content2&#34; ContentPlaceHolderID=&#34;MainContent&#34; runat=&#34;Server&#34;&gt; &lt;div class=&#34;jumbotron&#34;&gt; &lt;h1&gt;ASP.NET&lt;/h1&gt; &lt;p class=&#34;lead&#34;&gt; ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.&lt;/p&gt; &lt;p&gt;&lt;a href=&#34;http://www.asp.net&#34; class=&#34;btn btn-primary btn-lg&#34;&gt;Learn more &amp;raquo;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class=&#34;row&#34;&gt; &lt;div class=&#34;col-md-4&#34;&gt; &lt;h2&gt;Getting started&lt;/h2&gt; &lt;p&gt; 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. &lt;/p&gt; &lt;p&gt;&lt;a class=&#34;btn btn-default&#34; href=&#34;https://go.microsoft.com/fwlink/?LinkId=301948&#34;&gt;Learn more &amp;raquo;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class=&#34;col-md-4&#34;&gt; &lt;h2&gt;Get more libraries&lt;/h2&gt; &lt;p&gt; NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects. &lt;/p&gt; &lt;p&gt;&lt;a class=&#34;btn btn-default&#34; href=&#34;https://go.microsoft.com/fwlink/?LinkId=301949&#34;&gt;Learn more &amp;raquo;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class=&#34;col-md-4&#34;&gt; &lt;h2&gt;Web Hosting&lt;/h2&gt; &lt;p&gt; You can easily find a web hosting company that offers the right mix of features and price for your applications. &lt;/p&gt; &lt;p&gt;&lt;a class=&#34;btn btn-default&#34; href=&#34;https://go.microsoft.com/fwlink/?LinkId=301950&#34;&gt;Learn more &amp;raquo;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/asp:Content&gt; </pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><span style="text-decoration: underline;">Print Preview</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/bUBcX6V.jpg" alt="" width="472" height="335" /></span></p>https://www.aspforums.net:443/Threads/167779/Print-Page-having-Master-Page-using-JavaScript-in-ASPNet/https://www.aspforums.net:443/Threads/167779/Print-Page-having-Master-Page-using-JavaScript-in-ASPNet/Mon, 10 Jun 2019 01:28:32 GMT