A页如何触发B页事件(aspx)

fayxue 2012-06-02 07:14:57
A页如何触发B页事件(aspx).

比如当前打开了一个页面a.aspx,再通过超链接或者按钮打开了b.aspx 同时保留a页。

如何在b页进行某些操作完成后 关闭时触发a.aspx的某个事件来加载一些最新数据??

不要重新打开a页,因为a页或许已经填写过某些资料,就解决这么一问题。

用什么来解决都行,.net事件 javascipt都行
...全文
208 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ahoo 2012-06-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:

------------------------------

parent.htm

<script>

str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");

……
[/Quote]
+
dulei19900815dulei 2012-06-05
  • 打赏
  • 举报
回复
public void WriteJavaScript(string js)
{
try
{
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script language='javascript' defer>" + js.Trim() + ";</script>");
}
catch (Exception ex)
{
throw ex;
}
}
dulei19900815dulei 2012-06-05
  • 打赏
  • 举报
回复
在A页面写一个refresh事件,然后在B页面用 WriteJavaScript("alert('保存成功!');window.opener.refresh(1);window.close();");
whqjj2006 2012-06-05
  • 打赏
  • 举报
回复
小的地方用session就可以了
fayxue 2012-06-05
  • 打赏
  • 举报
回复
写了个小例子

A页代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function aa() {
str = window.showModalDialog('PageEventBack2.aspx', '', 'dialogWidth=400px;dialogHeight=200px;');
document.getElementById("Button2").click();//刷新数据列表
alert(str);
}
  </script>


</head>
<body>
<form id="form1" runat="server">
<input id="Button1" type="button" value="添加数据" onclick="javascript:aa();" />
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" style="display:none"/>//加个隐藏按钮为js调用
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}

public void BindData()
{
DataSet ds = new DataSet();
ds = bll.GetList(string.Empty);
GridView1.DataSource = ds;
GridView1.DataBind();
}

protected void Button2_Click(object sender, EventArgs e)//这个事件就为了重新绑定数据
{
BindData();
}






B页代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<base target="_self"/>---------不加这句的话提交后会再次打开新窗口 很烦
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;" cellpadding="2" cellspacing="1" class="border">
<tr>
<td class="tdbg">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td height="25" width="30%" align="right">
text :
</td>
<td height="25" width="*" align="left">
<asp:TextBox ID="txttext" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="tdbg" align="center" valign="bottom">
<asp:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click">
</asp:Button>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

protected void btnSave_Click(object sender, EventArgs e)
{
各种操作..............

Page.ClientScript.RegisterStartupScript(GetType(), string.Empty, "<script>window.returnValue='success';window.close();</script>");//完事后关闭当前小窗口
}
fayxue 2012-06-05
  • 打赏
  • 举报
回复
不用javascript可以吗??
蝶恋花雨 2012-06-02
  • 打赏
  • 举报
回复
参考
js关闭子窗体,父窗体的数据自动刷新
http://www.copy568.com/post/20120329632.html
http://www.cnblogs.com/wenjl520/archive/2010/07/08/1773456.html
http://hi.baidu.com/jane571531/blog/item/cb632419b995bf0f34fa416b.html
阿非 2012-06-02
  • 打赏
  • 举报
回复
fayxue 2012-06-02
  • 打赏
  • 举报
回复
可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:

  ------------------------------

  parent.htm

  <script>

  str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");

  alert(str);

  </script>

  modal.htm

  <script>

  window.returnValue="http://www.51js.com";

  </script>

lovebaby 2012-06-02
  • 打赏
  • 举报
回复
模态窗口吧
evelyn_green 2012-06-02
  • 打赏
  • 举报
回复
AJAX行吗
  • 打赏
  • 举报
回复
用js搞定哦,B页面调用母页面的 方法/按钮点击 都可以的
happytonice 2012-06-02
  • 打赏
  • 举报
回复
这个问题可以解决,不过不是用点击链接打开,打开个模式窗口就行。其他的找度娘

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧