Problem:-Click on print button in a web application page.then click on print button of print dialog box.A save dialog box will get open,wait for 5 or 10 minutes approximately.
save the file with any name. click on cancel. page is navigating to page äs internet explorer cannot display the webpage.
Search.apx.cs
protected void btnPrint_Click(object sender, EventArgs e)
{
XPathDocument messXpathDoc = new XPathDocument(Server.MapPath("~/XMLFiles/Messages.xml"));
messXPathNav = messXpathDoc.CreateNavigator();
if (RadGrid1.Items.Count == 0)
{
errorSpan.InnerHtml = GetMessageValue(messXpathIter, messXPathNav, "Messages/NO_ROWS_TO_PRINT");
this.errorSpan.Attributes["class"] = "EMBMessageSystemhilight";
return;
}
RadGrid1.Columns[12].Visible = false;
RadGrid1.Columns[13].Visible = false;
//VAMII-JIRA 251
RadGrid1.CurrentPageIndex = 0;
RadGrid1.MasterTableView.AllowPaging = false;
RadGrid1.MasterTableView.Rebind();
int i = RadGrid1.Items.Count;
HidingExpandCollapseImages(RadGrid1.MasterTableView);
foreach (GridItem item in RadGrid1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Pager}))
item.Display = false;
ClientScript.RegisterStartupScript(Page.GetType(), "PrintScript", "PrintRadGrid1('" + RadGrid1.ClientID + "');", true);
}
Search.aspx
<script type="text/javascript">
function PrintRadGrid1(radGridId) {
var radGrid = $get(radGridId);
var previewWnd = window.document.open('about:blank', '', 'width=1,height=1,toolbar=0,scrollbars=0,status=0,resizable=no,location=no,menubar=no', false);
var appPath = 'http://localhost:3759/TivoliWebProxy'; // Only for local testing
var sh = '<%= ClientScript.GetWebResourceUrl(RadGrid1.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",RadGrid1.Skin)) %>';
var styleStr = "<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
var cssStr = "<style type='text/css'>TH {background-color:ffffff !important;color:Blue;}TH A {text-decoration:underline;}TH SPAN {text-decoration:underline;}</style>";
var tempcontent = radGrid.outerHTML;
__doPostBack('_Self', "SearchEnablePaging");
var ind1 = tempcontent.toLowerCase().indexOf('<colgroup>');
var ind2 = tempcontent.toLowerCase().indexOf('</colgroup>')
tempcontent = tempcontent.replace(tempcontent.substr(ind1, (ind2 - ind1) + '</colgroup>'.length), "");
var htmlcontent = styleStr + cssStr + "<body>" + tempcontent + "</body></html>";
previewWnd.document.write(htmlcontent);
previewWnd.document.close();
previewWnd.print();
previewWnd.close();
}
</script>