Saturday, June 25, 2011

How to: perform page break by printing ASP.NET Web forms

Once we created an ASP.NET Web Application having web forms the next request was to organize carbon copy of these forms: do print them and support page breaks.

The solution is:

  • declare dedicated div style class for separate print pages
  • add page-break-after: always; property to this class
  • enclose the print pages in separate div elements and set their style to the class declared above

Example:

the ASP.net Form:

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="WebForm.aspx.cs"Inherits="WebForm"%>
<!DOCTYPEhtml PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
htmlxmlns
="http://www.w3.org/1999/xhtml">
<
headrunat
="server">
    <
styletype="text/css"media
="screen">
      
.formLabel
      
{
            min-width: 100px;
            color: Blue;
        }
       
.formTextBox
      
{
            width: 200px;
        }
    </style
>
    <
styletype="text/css"media
="print">
      
.formLabel
      
{
            min-width: 100px;
            color: Black;
        }
       
.formPage
      
{
            page-break-after: always;
        }
       
.formTextBox
      
{
            width: 200px;
        }
    </style
>
    <
title>Department Form</title
>
</
head
>
<
body
>
    <
formid="form1"runat
="server">
    <
div
>
        <
divclass
="formPage">
            <
asp:LabelID="LabelName"runat="server"Text="Name:"CssClass="formLabel"Width="100px"></asp:Label
>
            <
asp:TextBox ID="TextBoxName"runat="server"CssClass="formTextBox"></asp:TextBox
>
            <
br
/>
            <
asp:LabelID="LabelPhone"runat="server"Text="Phone:"CssClass="formLabel"Width="100px"></asp:Label
>
            <
asp:TextBox ID="TextBoxPhone"runat="server"CssClass="formTextBox"></asp:TextBox
>
            <
br
/>
        </
div
>
        <
divclass
="formPage">
            <
asp:LabelID="LabelAddress"runat="server"Text="Address:"CssClass
="formLabel"
              
Width="100px"></asp:Label
>
            <
asp:TextBox ID="TextBoxAddress"runat="server"CssClass="formTextBox"></asp:TextBox
>
            <
br
/>
            <
asp:LabelID="LabelRegPlate"runat="server"Text="Reg. Plate:"CssClass
="formLabel"
              
Width="100px"></asp:Label
>
            <
asp:TextBox ID="TextBoxRegPlate"runat="server"CssClass="formTextBox"></asp:TextBox
>
            <
br
/>
        </
div
>
    </
div
>
    </
form
>
</
body
>
</
html
>

The form in browser:
image

The form in print view:

imageimage

Enjoy!

Wednesday, June 22, 2011

Troubleshooting Firefox 5 and delicious bookmarks

Firefox 5 is here, and the problem described here appears again.

Use the same “cure”: change “4.*” to “5.*” and enjoy!

Wednesday, June 15, 2011

TFS 2008 Problem: Unable to connect to the Windows SharePoint Services

Assume, you plan to create a new TFS project using TFS 2008. Everything goes well up to the last step - then an error dialog appears saying “Unable to connect to the Windows SharePoint Services at <URI>”:

image

The reason is, the TFS instance cannot create the Sharepoint Portal for the project. More information is to find in the error log file on the TFS server.

Most popular problem are changed connection properties to Sharepoint instance (for example, port number). In this case the log file contains message, that the server rejects the connection on used URI.
(We discounter this error due to uncoordinated change in Sharepoint configuration, where the port number was altered in mistake).

OK, two things to take away.

1. Show the current TFS settings.

Log-in to TFS server, got to the TFS program files folder, the to the “Tools” subfolder – here you find the TfsAdminUtil: administration utility for TFS.

Start it using following command line:

TfsAdminUtil configureconnections

You see all the important current settings for local TFS instance:

image

2. Change required setting

For this task TfsAdminUtil offers set of keys/options:

x10sctmp0

For example, use /SharepointAdminUri: to change Sharepoint Administration URI:

TfsAdminUtil configureconnections /SharepointAdminUri:http://myserver:myport/_vti_adm/admin.asmx

Think about full path to the administration service file (.asmx), not just admin site URL!

image

Use TfsAdminUtil to view changed settings as shown above, restart TFS server and enjoy!