例如如下几个页面,想要实现在页面1中输入信息点击发送后,页面2立即显示所输入的信息
前端代码为:
<form id="form1" runat="server" method="post">
<div class="container main" style="height:600px;">
<div class="h4" style="text-align:center;">聊天室</div>
<div id="left">
<iframe src="List.aspx" name="left" scrolling="no" width="300px" height="460px" frameborder="0"></iframe>
</div>
<div id="right">
<iframe src="Content.aspx" name="right" scrolling="no" width="860px" height="460px" frameborder="0"></iframe>
</div>
<div id="bootom">
<iframe src="Bottom.aspx" name="bootom" scrolling="no" width="1170px" height="95px" frameborder="0"></iframe>
</div>
</div>
</form>
其中left是页面3,right是页面2,bootom是页面1
1.首先在主页面添加如下js代码:
<body>
<form id="form1" runat="server" method="post">
<div class="container main" style="height:600px;">
<div class="h4" style="text-align:center;">聊天室</div>
<div id="left">
<iframe src="List.aspx" name="left" scrolling="no" width="300px" height="460px" frameborder="0"></iframe>
</div>
<div id="right">
<iframe src="Content.aspx" name="right" scrolling="no" width="860px" height="460px" frameborder="0"></iframe>
</div>
<div id="bootom">
<iframe src="Bottom.aspx" name="bootom" scrolling="no" width="1170px" height="95px" frameborder="0"></iframe>
</div>
</div>
</form>
<script>
function refreshRight() {
right.window.location.reload();
}
</script>
</body>
2.在页面1发送按钮的点击事件中添加如下代码:
protected void Button1_Click(object sender, EventArgs e)
{
....以上为其他逻辑代码
string parentJs = @"<script>parent.refreshRight();</script>";
ClientScript.RegisterStartupScript(this.GetType(), "clientScript", parentJs);
}
然后就大功告成了,小伙伴们赶紧去试试吧!