如何在弹出的窗口中引发父窗口的postback事件

本文介绍了一种在弹出窗口中触发父窗口Postback的方法。通过JavaScript与ASP.NET结合使用,实现在子窗口中操作引发父窗口的Postback事件,以此来更新父窗口的数据状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

看到一篇老外的介绍,介绍如何在弹出的窗口中引发父窗口的postback事件,现转载如下:
首先,建立main.aspx文件,写入如下代码,其中的一个按钮设置为visiable,只是为了效果而设置。
<script language="javascript">
//To cause postback "as" the Button
function PostBackOnMainPage(){
<%=Page.GetPostBackEventReference(btnPostBack)%>
}
//Helper just to open popup
function openPopUp(){
window.open('popup.aspx','popup','width=400,height=100');
//Maybe handling something else also, like giving extra arguments etc etc
}

</script>
<script runat="server" language="VB">
'This is to react to the postback
Protected Sub btnPostBack_Click(ByVal sender As Object, ByVal e As EventArgs)
lblShowPostInfo.Text = "Postback happened: " & DateTime.Now.ToString()
End Sub
</script>
<form id="Form1" method="post" runat="server">
<input type="button" onclick="openPopUp()" value="Open the popup">
<asp:Button ID="btnPostback" runat="server" Visible="false" OnClick="btnPostBack_Click" />
<asp:Label ID="lblShowPostInfo" runat="server" />
</form>
可以看到,button按钮引发openpopup的事件,弹出窗口。为了明显,设置一个文本lblshowpostinfo,显示引发postback的时间.而在popup.aspx中,代码如下:
<input type=button onclick="opener.PostBackOnMainPage()" value="Cause a postback on opening page" />

作用是点这个按钮,引发父窗口的postbackonmainpage()事件


来自Wang_Zemin闲的蛋疼时候写的空间搬家工具
文章迁移自我的百度空间 o0o王泽民o0o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值