Friday, October 31, 2008

Why IE only prints the first page?

A few days ago, an issue was escalated to me that one of the web report can only print one (first) page in IE, even the report has three pages. It appeared in Print Preview that there is only one page. But if you look it in Firefox 3.0, you can see three pages in preview and can print all three pages.

The problem is with the css file (Cascade style sheet) with "absolute" keyword.

In the CSS file referred in the webpage, there is a section like this:
div.outbox
{
position: absolute;
left: 65px;
top: 30px;
}

When the page has a DIV tag called the class as <DIV class="outbox" >, or you have a tag like <div style="position:absolute; left:65px; top:30px;" >, IE will mis-interpret the keyword and stop at first page.

In the next example, I changed the keyword "absolute" to "relative":
.outbox2
{
position: relative;
left: 65px;
top: 30px;
}

This solved the "IE only prints first page" issue.

If you encountered similar error and solved with different methods or a different tag/keyword caused the error, please kindly post a comment here to share with other viewers. Thanks.

Wednesday, October 15, 2008

Smalldatetime error

If you see this error:
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value

it means you have bad date to convert from string to smalldatetime data type in database. It usually occurs when you have a web form that submitted some data to save into database and one of the data is a date string.

For some reason, people will type the date wrong such as 1/1/2008 becomes 1/1/2998. But the smalldatetime data type can only hold a date smaller than June 6 2079.

For ASP.NET, you can add this to your customized validation:

Private Sub ValidateStartDate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
Dim IsValid As Boolean = False
Dim strSalesDate As String
strSalesDate = Clean(Me.txtAdStart.Text)
If IsDate(strSalesDate) Then
IsValid = True
Dim intYear As Integer
intYear = Year(CDate(strSalesDate))
If intYear > 2075 Then
IsValid = False
End If
End If
args.IsValid = IsValid
End Sub