如何从弹出窗口返回值

时间:2021-02-21 07:16:21

I am using asp.net webforms 2.0, c#.

我正在使用asp.net webforms 2.0,c#。

What I need is a simple, elegant way to do the following:

我需要的是一种简单,优雅的方式来执行以下操作:

User clicks an element in webform A; Webform B pops up; User interracts with webform B; On closing webform B, probably by a submit button, the source element in webform a a is updated with a value from webform B.

用户单击webform A中的元素; Webform B弹出;用户与webform B交互;在关闭webform B时,可能通过提交按钮,webform a中的source元素将使用webform B中的值进行更新。

What technologies would be involved here? Aside from Javascript and c#, of course. Can I do it without Ajax?

这里涉及哪些技术?当然,除了Javascript和c#之外。没有Ajax我可以做到吗?

EDITED:

To clarify, WEBform B will save the data entered into the database, say customer information, then it will come back with the customer ID (after saving), this customer ID needs to be passed to the parent window, which should refresh after this.

为了澄清,WEBform B将保存输入数据库的数据,比如客户信息,然后它会带回客户ID(保存后),这个客户ID需要传递给父窗口,之后应该刷新。

3 个解决方案

#1


You can use JavaScript:

你可以使用JavaScript:

<script language="javascript">
window.opener.location.reload();
self.close();
</script>

The above code shows how to close the 'opener' window, but it should give you the general idea. (This code is in the Popup window). You can use the same method to pass values to the 'opener' window by calling JavaScript function within it.

上面的代码显示了如何关闭'开启者'窗口,但它应该给你一般的想法。 (此代码位于弹出窗口中)。您可以使用相同的方法通过调用其中的JavaScript函数将值传递给'opener'窗口。

<script language="javascript">
window.opener.functionA('ABC123');    
</script>

If you want to pass a variable from your ASP into the JavaScript function, use:

如果要将ASP中的变量传递给JavaScript函数,请使用:

window.opener.functionA('<%=userId%>');

or

var userId = '<%=userId%>';
window.opener.functionA( userId );

Hope that helps!

希望有所帮助!

#2


If you are using ASP.NET 2.0, you can have the second page post back to the first and then detect it with IsCrossPagePostBack.

如果您使用的是ASP.NET 2.0,则可以将第二页回发到第一页,然后使用IsCrossPagePostBack检测它。

#3


function webFormAClick(){ var theReturnValue = window.showModalDialog("webFormB.html", myArguments, ''); }

#1


You can use JavaScript:

你可以使用JavaScript:

<script language="javascript">
window.opener.location.reload();
self.close();
</script>

The above code shows how to close the 'opener' window, but it should give you the general idea. (This code is in the Popup window). You can use the same method to pass values to the 'opener' window by calling JavaScript function within it.

上面的代码显示了如何关闭'开启者'窗口,但它应该给你一般的想法。 (此代码位于弹出窗口中)。您可以使用相同的方法通过调用其中的JavaScript函数将值传递给'opener'窗口。

<script language="javascript">
window.opener.functionA('ABC123');    
</script>

If you want to pass a variable from your ASP into the JavaScript function, use:

如果要将ASP中的变量传递给JavaScript函数,请使用:

window.opener.functionA('<%=userId%>');

or

var userId = '<%=userId%>';
window.opener.functionA( userId );

Hope that helps!

希望有所帮助!

#2


If you are using ASP.NET 2.0, you can have the second page post back to the first and then detect it with IsCrossPagePostBack.

如果您使用的是ASP.NET 2.0,则可以将第二页回发到第一页,然后使用IsCrossPagePostBack检测它。

#3


function webFormAClick(){ var theReturnValue = window.showModalDialog("webFormB.html", myArguments, ''); }