asp.net---iframe切分頁面,區域性重新整理,一個頁面的點選事件在另一個頁面響應
阿新 • • 發佈:2019-02-11
例如如下幾個頁面,想要實現在頁面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);
}
然後就大功告成了,小夥伴們趕緊去試試吧!