[英]Calling Javascript in C#
如何在c#linkbutton_click事件中调用以下javascript。 下面的代码在aspx页面上,我想从后面的代码中调用它
<script type="text/javascript">
function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=1000,width=900');
printWindow.document.write('<html><head>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>
将此添加到linkbutton_click
Type myType = this.GetType();
//You may not need this if statement
if (!ClientScript.IsClientScriptBlockRegistered(someType, "_linkbutton_click"))
{
string script = "PrintPanel;";
ClientScript.RegisterClientScriptBlock(someType, "_linkbutton_click", script, true);
}
您可以在链接按钮的OnClientClick
上调用该函数。
添加OnClientClick="return PrintPanel();"
到您的LinkButton
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.