Y
yoga weazel
OK, so let me start with what I'm trying to accomplish.
I have several screens with data displays using various controls (DataList,
DataGrid...). I need to provide functionality so that the user can click a
"Printable Version" button and a clean print formatted version of the data
chosen is displayed in a new window. I'd prefer to do as much of this client
side as possible so data services are not re-hit and not storing extraneous
data in Session or View state.
The approach I have currently is to provide a button which when clicked
calls javascript to open the GenericPrintReport.aspx page with the ID of the
original documents HTML element to print and the name of a XSL stylesheet to
use in a new window. The body of the GenericPrintReport.aspx page contains
the following javascript:
<pre>
<script language="javascript" type="text/javascript">
//get data from parentwindow.ctrl
var ctrl =
window.opener.document.getElementById('<%=Request.Params("CtrlId") %>');
//set DivData content to data
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
// make sure to remove any invalid XML (such as )
var ctrlText = '<?xml version="1.0" encoding="UTF-16"?>' +
ctrl.innerHTML.replace(/\ \;/gi, "");
xml.loadXML(ctrlText); // Load XML Content
document.write("<br>Error Code: ")
document.write(xml.parseError.errorCode)
document.write("<br>Error Reason: ")
document.write(xml.parseError.reason)
document.write("<br>Error Line: ")
document.write(xml.parseError.line)
// load the requested transformation
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
var xslFilename = '<%=Request.Params("Transform") %>';
if (xslFilename.length > 0)
{
xsl.load('<%=Request.Params("Transform") %>'); // Transformation
}
else
{
xsl.load('default.xsl');
}
// write results to output
var transformedXml = xml.transformNode(xsl);
document.write(transformedXml);
</script>
</pre>
OK. So now the problem... When using some of the .NET controls (e.g.
DataGrid) the HTML generated at runtime is not XHTML compliant therefore the
xml.loadXML(ctrlText) call gets a parse error:
Error Code: -1072896766
Error Reason: A string literal was expected, but no opening quote character
was found.
Error Line: 1
Since several of the attributes generated by the controls aren't contained
in quote characters.
Is there a way to change the behavior of the parser used by Microsoft.XMLDOM
or change the way the HTML is generated by the framework WebControls? Or is
there another way around this problem (besides writing my own pre-parser to
clean the HTML)? Thanks.
Yoga Weazel
- Eagles may soar but weasels don't get sucked into jet engines.
I have several screens with data displays using various controls (DataList,
DataGrid...). I need to provide functionality so that the user can click a
"Printable Version" button and a clean print formatted version of the data
chosen is displayed in a new window. I'd prefer to do as much of this client
side as possible so data services are not re-hit and not storing extraneous
data in Session or View state.
The approach I have currently is to provide a button which when clicked
calls javascript to open the GenericPrintReport.aspx page with the ID of the
original documents HTML element to print and the name of a XSL stylesheet to
use in a new window. The body of the GenericPrintReport.aspx page contains
the following javascript:
<pre>
<script language="javascript" type="text/javascript">
//get data from parentwindow.ctrl
var ctrl =
window.opener.document.getElementById('<%=Request.Params("CtrlId") %>');
//set DivData content to data
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
// make sure to remove any invalid XML (such as )
var ctrlText = '<?xml version="1.0" encoding="UTF-16"?>' +
ctrl.innerHTML.replace(/\ \;/gi, "");
xml.loadXML(ctrlText); // Load XML Content
document.write("<br>Error Code: ")
document.write(xml.parseError.errorCode)
document.write("<br>Error Reason: ")
document.write(xml.parseError.reason)
document.write("<br>Error Line: ")
document.write(xml.parseError.line)
// load the requested transformation
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
var xslFilename = '<%=Request.Params("Transform") %>';
if (xslFilename.length > 0)
{
xsl.load('<%=Request.Params("Transform") %>'); // Transformation
}
else
{
xsl.load('default.xsl');
}
// write results to output
var transformedXml = xml.transformNode(xsl);
document.write(transformedXml);
</script>
</pre>
OK. So now the problem... When using some of the .NET controls (e.g.
DataGrid) the HTML generated at runtime is not XHTML compliant therefore the
xml.loadXML(ctrlText) call gets a parse error:
Error Code: -1072896766
Error Reason: A string literal was expected, but no opening quote character
was found.
Error Line: 1
Since several of the attributes generated by the controls aren't contained
in quote characters.
Is there a way to change the behavior of the parser used by Microsoft.XMLDOM
or change the way the HTML is generated by the framework WebControls? Or is
there another way around this problem (besides writing my own pre-parser to
clean the HTML)? Thanks.
Yoga Weazel
- Eagles may soar but weasels don't get sucked into jet engines.