一、UserControl调用所在页面的其他内容(代理实现)
UserControl代码
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;
public partial class UserControl_Welcome : System.Web.UI.UserControl
{
public delegate void ButtonClickEventHandler(object sender, EventArgs e);
public event ButtonClickEventHandler ButtonClick;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOrder_Click(object sender, EventArgs e)
{
ButtonClick(sender,e);
}
}
页面代码
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Welcome1.ButtonClick += new UserControl_Welcome.ButtonClickEventHandler(Welcome_ButtonClick);
}
public void Welcome_ButtonClick(object sender, EventArgs e)
{
TabContainer1.ActiveTabIndex = 1;
//由于用的AJAX控件,所以完成后AJAX控件要手动更新
UpdatePanel5.Update();
}
二、javascript实现部分打印
1、在页面的代码头活末尾部处加入JavaScript:
Code
<script language=javascript>
function doPrint() {
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
2、在页面正文处加上<!--startprint-->与<!--endprint-->标识。
3、添加打印按钮,执行JavaScript