Hi Telerik,
I've created a page which I populate all grids on the page programmatically in c# and following this demo to print the grids; however as my grids are created on pageload, when typing the javascript code in front end (aspx), the script cannot detect the grids and returning a "The Name 'RadGrid1' does not exist in current content" error. I've tried calling it by string name in the $find function and also tried document.FindElementById, but no luck. Could anyone give me some advice on this issue?
Many thanks.
Attached the code below:
I've created a page which I populate all grids on the page programmatically in c# and following this demo to print the grids; however as my grids are created on pageload, when typing the javascript code in front end (aspx), the script cannot detect the grids and returning a "The Name 'RadGrid1' does not exist in current content" error. I've tried calling it by string name in the $find function and also tried document.FindElementById, but no luck. Could anyone give me some advice on this issue?
Many thanks.
Attached the code below:
function Print() { var previewWindow = window.open('about:blank', '', '', false); var styleSheet = '<%= Telerik.Web.SkinRegistrar.GetWebResourceUrl(this, RadGrid1.GetType(), String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css", RadGrid1.Skin)) %>'; var baseStyleSheet = '<%= Telerik.Web.SkinRegistrar.GetWebResourceUrl(this, RadGrid1.GetType(), "Telerik.Web.UI.Skins.Grid.css") %>'; var htmlContent = "<html><head><link href = '" + styleSheet + "' rel='stylesheet' type='text/css'></link>"; htmlContent += "<link href = '" + baseStyleSheet + "' rel='stylesheet' type='text/css'></link></head><body>"; for (i = 1; i < 13; i++) { var CYGrid = "RadGrid_CY_Strategy_" + String(i); var CYradGrid = $find('<%=CYGrid.ClientID %>'); //This is not working well, hence below htmlContent += getOuterHTML(CYradGrid.get_element()); if (LYradGrid.hidden == false) { htmlContent += getOuterHTML(LYradGrid.get_element()); } } htmlContent += "</body></html>"; previewWindow.document.open(); previewWindow.document.write(htmlContent); previewWindow.document.close(); previewWindow.print(); if (!$telerik.isChrome) { previewWindow.close();} function getOuterHTML(obj) { if (typeof (obj.outerHTML) == "undefined") { var divWrapper = document.createElement("div"); var copyOb = obj.cloneNode(true); divWrapper.appendChild(copyOb); return divWrapper.innerHTML } else { return obj.outerHTML; }}