HIDING CONTROLS WHEN PRINTING WITH WINDOW.PRINT()

Sometimes in web applications (ASP.NET) we prefer printing a window without some controls that appear on the interface. For example, printing a window by clicking on a print button without showing the print button on the printed document. In this example we are printing a student’s results without showing the Print and the close buttons.

To start, we place the two control in a DIV control.Drag the “DIV” control from the HTML controls section. Name the DIV control by giving a value to ID property as shown below. Place the print and close button in the DIV control.

clip_image002

Note that in creating ASP.NET applications, there are two types of source codes, the VB/C# source code and the HTML code. First we create a script to hide the DIV control as shown below. In the script below the “dv1” is the ID value of the DIV control

Add this script to the HTML source

   1: <script language="javascript" type="text/javascript">

   2:    function hidePrint(){

   3:     document.getElementById("dv1").style.display='none';

   4:     window.print();

   5:     window.close();

   6:             }

   7: </script>

Note that the script should be in between the <head></head> tag of the html source code

Select the print button and go to the html source code and add the onclick property . The value of the onclick property should be the created javascript function (named hidePrint()). The button’s html code should look like the one below after the addition of the onclick property

   1: <input type="button" id="Button1" runat="server" 

   2: value="Print" class="fltbutton"  style="width:60px" 

   3: onclick="javascript:hidePrint();" />

This is all you have to do and you are good to go.

Below is a window showing the student’s results and the Print and the Close Button

clip_image004

What is printed after clicking on the “print” button

clip_image006

Cheers!!!!

Advertisements

DEPLOYING ASP.NET APPS USING IIS 7

You have finished developing your ASP.net application using VS 2005 in Windows Vista environment and you need to deploy, just go ahead and deploy in the vista environment, you do not have to look for Windows XP before you can do this. Here are few steps to follow to deploy your application using IIS 7 .

  1. First make sure all the components of the IIS server is installed on your system. To do this, Go to Start > Control Panel >Programs and Features and the click on the "Turn Windows features on or off" on the left task pane of the window as shown below.

  2. On the windows feature dialog box that pops up, make sure the Internet Information Service node and all its child nodes are checked as shown below or else get your original Windows Vista CD, check all the nodes and install these features.

  3. To access the IIS Manager after the installation, Go to Start>Control Panel>Administrative Tools >Internet Information Services (IIS) Manager or go to run (Window Key + R) and enter "inetmgr" and you will get an interface like the one below.

  4. Now we are good to go on and deploy our ASP.Net Web Application. Navigate to the Default Web Site Node, then right click on it and choose "Add Application" from the context menu. A dialog box will pop up as shown below. The alias is the name of your website, for example if you enter Ghana, or accra , or kumasi, when accessing your website from your local computer, you will be typing "localhost/Ghana, or localhost/accra, or localhost/Kumasi"

    Click on the "Physical path:" button to browse for the website folder of your application and click on the "OK" button.

  5. A new node with the name you entered in the alias textbox will appear under the "Default Web Site" node. Select the node, and make sure your connection string, default documents are set to the required values. The picture below clarify these

  6. After making the required changes, you are done. Make sure your IIS server is running (you can check this by clicking on the "Default Web Site" node and on the right task pane, under manage web site, make sure the "star" link is disabled else click on it to start the server). Go to your browser and enter your URL, in this case "http://localhost/ghana&quot; or right click your application from IIS GUI and select browse.