We have a custom print button on an aspx page. The button is using the following code to open a new page with the print dialog. All elements are appearing correctly in the print preview except the dropdownlist that has a lot of items. Other dropdownlist selected values are appearing correctly but they have 5-6 items only.
However if I print->cancel->print , the second time the preview print page is displayed, the selected value of the drop down is displayed correctly. Ctr+P works correctly too but it prints the entire page (not required). This issue is same for chrome/firefox/edge
<script type="text/javascript">
function CallPrint(strid) {
var WinPrint = window.open('', "", 'width=1500,height=1500');
var prtContent = document.getElementById(strid);
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.write('<link rel=stylesheet href=StyleSheet.css>')
WinPrint.document.close();
WinPrint.onload = function () { // wait until all resources loaded
WinPrint.focus();
WinPrint.print();
WinPrint.close();
};
setTimeout(window.close, 500);
return true;
}
</script>
part of the aspx
<div id="print"> ......
<td class="auto-style162">
<ajaxToolkit:ComboBox ID="dd_aj" runat="server" AutoCompleteMode="Suggest" DataSourceID="sql_aj" DataTextField="Job_No" DataValueField="Job_Key" DropDownStyle="DropDownList" MaxLength="0" Style="display: inline;">
</ajaxToolkit:ComboBox>
</td> .....
<asp:Button ID="BtnPrint" runat="server" Text="Print" OnClientClick="javascript:CallPrint('print');" CssClass="alert info" />
</div>
Same result with a standard (non ajaxtoolkit) dropdown list.
I am aware of using CSS Media print, but we cannot use that for now.
I have tried using the setTimeout and looked at other threads here like asp.net Printing Page using javascript
I am suspecting that since the dropdown has many items it takes too long to render.