Exporting or printing cause an object required JavaScript error in .NET Crystal Reports XI R2 web applications

No.of Views4460
Bookmarked0 times
Downloads 
Votes0
By  RRaveen   On  13 Apr 2011 04:04:10
Tag : Crystal Reports , Miscellaneous
This error "object required" in javascript, may be thrown in a .NET web application using the Crystal Reports XI R2 components. The error occurs when clicking on the "Ok" button in the export or print dialog window.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article, i will explain how to fix the a important javascript error with crystal report export or print screen in version 11 R2.

Problem

The JavaScript error "object required" may be thrown in a .NET web application using the Crystal Reports XI R2 components. The error occurs when clicking on the "Ok" button in the export or print dialog window.

When you click Ok button to print or export, you able to see this error ,

opener.document.getElementById("crystal_handler_page") is null

 

Cause

This error is caused because the export.js file is not updated after Service Pack 2 is installed for Crystal Reports XI R2. Before Service Pack 2 the line on 105 of export.js look like this:

" document.dlgform.action = opener.document.getElementById(\"crystal_handler_page\").value;" +

After Service Pack 2 line 105 looks like this:

" document.dlgform.action = opener.location;" +

This problem could happen with custom web sites where the crystalreportviewers115 is copied into a new folder. The new folder is not updated by service or fix packs provided by Business Objects. Only the following export.js files are updated by service and fix packs:

  1. Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\crystalreportviewers115\js\export.js
  2.  Program Files\Business Objects\Common\3.5\crystalreportviewers115\js\export.js
  3. WINDOWS\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles\crystalreportviewers115\js\export.js

Resolution

To resolve this issue you will need to modify the export.js files on your system. The best way to do that is to search the entire C:\ drive for "export.js". There are three possible locations for the export.js files and possibly more if copies have been made.

  1. Right click your C:\ drive and select "Search..."
  2. Type in "export.js" and click the "Search" button
  3. Take note of all the export.js files found and only edit the ones found under crystalreportviewer115 directories.
  4. Replace line 105 in export.js that looks like this:
" document.dlgform.action = opener.document.getElementById(\"crystal_handler_page\").value;" +
    with this:
    " document.dlgform.action = opener.location;" +

Once you are replace correctlly, then you able see the code of export.js as like below

// export.js
// This file contains the funcitons needed to construct the HTML for the export / print dialog.
//
// Global variable
var print = false;		// default to export, so set print to false
var crystal_postback =
        "<INPUT type=\"hidden\" name=\"reportsource\" id=\"reportsource\"/>" +
        "<INPUT type=\"hidden\" name=\"viewstate\" id=\"viewstate\"/>";

function getPageTitle() {
	if (print) {
		return L_PrintPageTitle;
	}
	else {
		return L_ExportPageTitle;
	}
}

function getOptionsTitle() {
	if (print) {
		return L_PrintOptions;
	}
	else {
		return L_ExportOptions;
	}
}

function getFormatDropdownList() {
	if (print) {
		return "<INPUT type=\"hidden\" name=\"exportformat\" id=\"exportformat\" value=\"PDF\"/>";
	}
	else {
		var list =
		"<select id=\"exportformatlist\" class=\"crexportselect\" name=\"exportformat\" onchange=\"checkDisableRange();\">";
		if( rpt )
		{
			list += "<OPTION value=\"CrystalReports\">" + L_CrystalRptFormat + "</OPTION>";
		}
		else
		{
			list += "<OPTION value=\"\">" + L_Formats + "</OPTION>";
		}
		if( pdf )
		{
			list += "<OPTION value=\"PDF\">" + L_AcrobatFormat + "</OPTION>";
		}
		if( xls )
		{
			list += "<OPTION value=\"MSExcel\">" + L_ExcelFormat + "</OPTION>";
		}
		if( recXls )
		{
			list += "<OPTION value=\"RecordToMSExcel\">" + L_ExcelRecordFormat + "</OPTION>";
		}
		if( word )
		{
			list += "<OPTION value=\"MSWord\">" + L_WordFormat + "</OPTION>";
		}
		if( ertf )
		{
			list += "<OPTION value=\"EditableRTF\">" + L_EditableRTFFormat +"</OPTION>";
		}
		if( rtf )
		{
			list += "<OPTION value=\"RTF\">" + L_RTFFormat +"</OPTION>";
		}
		
		list += "</SELECT>"
		return list;
	}
}

function getSelectPageRangeSentence() {
	if (print) {
		return L_PrintPageRange;
	}
	else {
		return L_ExportPageRange;
	}
}

function getExportDialog() {
	var exportDialog =
		"<HTML>" +
		"<HEAD>" +
		"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../css/default.css\">" +

		"<script type=\"text/javascript\" src=\"../js/exportdialog.js\"></script>" +
		"<script type=\"text/javascript\">" +
		"	function checkValuesAndSubmit() {" +
		"		if (document.forms[\"dlgform\"].isRange != null &&" +
		"		    document.forms[\"dlgform\"].isRange[1].checked) {" +
		"			if (!isValidNumber(document.forms[\"dlgform\"].from.value) ||" +
		"			    !isValidNumber(document.forms[\"dlgform\"].to.value) ||" +
		"		    	    (parseInt(document.forms[\"dlgform\"].from.value, 10) > parseInt(document.forms[\"dlgform\"].to.value, 10))) {" +
		"				alert(\"" + L_InvalidPageRange + "\");" +
		"				return;" +
		"			}" +
		"		}" +
		"		if (document.forms[\"dlgform\"].exportformat != null &&" +
		"		    document.forms[\"dlgform\"].exportformat.value == \"\") {" +
		"			alert(\"" + L_ExportFormat + "\");" +
		"			return;" +
		"		}" +	
		"		document.dlgform.action =opener.location;" +
		"		document.dlgform.submit();" +
		"		document.getElementById(\"submitexport\").disabled = true;" +
		"	}" +
		"</script>" +
		"<TITLE>" + getPageTitle() + "</TITLE>" +
		"</HEAD>" +
		"<BODY class=\"crexportpage\" bottommargin=\"5\" topmargin=\"5\" onload=\"checkDisableRange();\">" +
		"<FORM name=\"dlgform\" method=\"POST\">" +
		crystal_postback +		
		"<TABLE cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\" valign=\"bottom\" halign=\"center\" border=\"0\">";

	if (!print) {
		exportDialog +=
		"  <TR><TD align=\"left\"><table width=\"100%\" border=\"0\">" + 
		"    <tr>" +
		"      <td width=\"35%\"><span class=\"crexportmessage\"><label for=\"exportformatlist\">" + L_Formats + "</label></span></td>" + 
		"      <td align=\"left\" width=\"65%\" class=\"crexportselect\">" + 
		getFormatDropdownList() +
		"      </td>" +
		"    </tr>" + 
		"  </table></TD></TR>" + 
		"  <TR><TD><hr class=\"crexportruler\"></TD></TR>";
	}

		exportDialog +=
		"  <TR><TD align=\"left\"><table width=\"100%\" border=\"0\">" +
		"    <tr>" +
		"      <td width=\"35%\"><span class=\"crexportmessage\">" + L_PageRange + "</span></td>" + 
		"      <td width=\"65%\" align=\"left\"><input type=\"radio\" id=\"radio1\" name=\"isRange\" value=\"all\" onclick=\"return toggleRangeFields(this);\"/><span class=\"crexportmessage\"><label for=\"radio1\">" + L_All + "</label></span></td>" + 
		"    </tr>" +
		"    <tr>" + 
		"      <td rowspan=\"2\"></td>" + 
		"      <td align=\"left\"><input type=\"radio\" id=\"radio2\" checked name=\"isRange\" value=\"selection\" onclick=\"return toggleRangeFields(this);\"/><span class=\"crexportmessage\"><label for=\"radio2\">" + L_Pages + "</label></span></td>" +
		"    </tr>" +
		"    <tr>" +
		"      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"crexportmessage\"><label for=\"from\">" + L_From + "</label></span>&nbsp;&nbsp;<input class=\"crexporttextbox\" type=\"text\" width=\"20\" size=\"6\" maxlength=\"6\" name=\"from\" value=\"1\">&nbsp;&nbsp;<span class=\"crexportmessage\"><label for=\"to\">" + L_To + "</label></span>&nbsp;&nbsp;<input class=\"crexporttextbox\" type=\"text\" width=\"20\" size=\"6\" maxlength=\"6\" name=\"to\" value=\"1\"></td>" +
		"    </tr>" +
		"  </table></TD></TR>" +
		"  <TR><TD><hr class=\"crexportruler\"></TD></TR>";
	
	if (print) {
		exportDialog +=
		"  <TR><TD>" +
		"    <input type=\"hidden\" name=\"exportformat\" value=\"PDF\">" +
		"    <table>" +
		"    <tr><td><span class=\"crexportmessage\">" + L_PrintStep0 + "</span></td></tr>" +
		"    <tr><td><span class=\"crexportmessage\">" + L_PrintStep1 + "</span></td></tr>" +
		"    <tr><td><span class=\"crexportmessage\">" + L_PrintStep2 + "</span></td></tr>" +
		"    </table>"+
		"  </TD></TR>";
	}

		exportDialog +=
		"  <TR valign=\"top\"><TD align=\"right\"><input class=\"crexportbutton\" id=\"submitexport\" type=\"button\" value=\"" + L_OK + "\" onclick=\"checkValuesAndSubmit();\"/>&nbsp;&nbsp;<input class=\"crexportbutton\" type=\"button\" value=\"" + L_Cancel + "\" onclick=\"window.close();\"/></TD></TR>" +
		"</TABLE>" +
		"</FORM>" +
		"</BODY>" +
		"</HTML>";

		return exportDialog;
}

 Note:It is important to only change the export.js files which are in crystalreportviewers115 directories

Hope help and save you time. thank you for reading.

 
Sign Up to vote for this article
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top