C# 缺少Div内容

C# 缺少Div内容,c#,javascript,asp.net,.net,C#,Javascript,Asp.net,.net,我有一个带有表对象的div,它填充了页面的onload事件 <div id="divcontent" runat="server"> <asp:Table id="tblcontent" runat="server" CellPadding="4" align="center" width="80%"> </asp:Table> </div> <div align="left" style ="width:90%;

我有一个带有表对象的div,它填充了页面的onload事件

<div id="divcontent" runat="server">
<asp:Table id="tblcontent" runat="server" CellPadding="4" align="center"   width="80%">      </asp:Table>
</div>     

<div align="left" style ="width:90%; padding-top:20px;">
<input value="Print" type="button" onclick="PrintDiv();"/>       
</div> 

我用下面的代码打开一个带有div内容的弹出窗口,以便只打印div内容:

<script type="text/javascript">

function PrintDiv() {

    var divToPrint = document.getElementById('divcontent');

    var popupWin = window.open('', '_blank', 'width=500,height=700');

    popupWin.document.open();

    popupWin.document.write('<html><body onload="window.print()">' +   divToPrint.innerHTML + '</html>');

    popupWin.document.close();
}

</script> 

函数PrintDiv(){
var divToPrint=document.getElementById('divcontent');
var popupWin=window.open(“”,"u blank’,“宽度=500,高度=700”);
popupWin.document.open();
popupWin.document.write(“”+divToPrint.innerHTML+“”);
popupWin.document.close();
}

但是当弹出窗口打开时,它是空的!!有人能说出原因吗?

如果您的页面有母版页,那么divcontent将不会在浏览器上显示id值,因为您已经设置了
runat=“server”
,所以使用控件的
ClientID
来获取div的呈现id

试试这个

function PrintDiv() {
    var divToPrint = document.getElementById('<%= divcontent.ClientID %>');

    var popupWin = window.open('', '_blank', 'width=500,height=700');
    popupWin.document.open();
    popupWin.document.write('<html><body onload="window.print()">' +   divToPrint.innerHTML + '</html>');
    popupWin.document.close();
}
函数PrintDiv(){
var divToPrint=document.getElementById(“”);
var popupWin=window.open(“”,"u blank’,“宽度=500,高度=700”);
popupWin.document.open();
popupWin.document.write(“”+divToPrint.innerHTML+“”);
popupWin.document.close();
}

如果您的页面有母版页,那么divcontent将不会在浏览器上显示id值,因为您已经设置了
runat=“server”
,所以使用控件的
ClientID
来获取div的呈现id

试试这个

function PrintDiv() {
    var divToPrint = document.getElementById('<%= divcontent.ClientID %>');

    var popupWin = window.open('', '_blank', 'width=500,height=700');
    popupWin.document.open();
    popupWin.document.write('<html><body onload="window.print()">' +   divToPrint.innerHTML + '</html>');
    popupWin.document.close();
}
函数PrintDiv(){
var divToPrint=document.getElementById(“”);
var popupWin=window.open(“”,"u blank’,“宽度=500,高度=700”);
popupWin.document.open();
popupWin.document.write(“”+divToPrint.innerHTML+“”);
popupWin.document.close();
}

哇,效果不错。我整天都在忙这个问题。提前谢谢哇,效果很好。我整天都在忙这个问题。提前谢谢