[英]Show the server-side generated HTML in a new window
What is the best way to show the server-side generated HTML (full page) into a new popup window? 将服务器端生成的HTML(全页)显示到新的弹出窗口中的最佳方法是什么? It should be triggered upon clicking a button (causing a postback to the server).
单击按钮后应触发它(导致回发到服务器)。
Thanks 谢谢
Edited: 编辑:
The HTML content are dynamically generated in the code behind and the content is full page ( <html> ... </html>
). HTML内容是在后面的代码中动态生成的,并且内容是整页(
<html> ... </html>
)。 Upon clicking a button on the web page, I would like to get the generated html content and pass it to the browser and show it in a new popup window. 单击网页上的按钮后,我想获取生成的html内容并将其传递给浏览器并在新的弹出窗口中显示。 The content will be the final result (UI) not HTML tags.
内容将是最终结果(UI),而不是HTML标记。
You can send the same page with mime type text/plain
您可以使用MIME类型
text/plain
发送同一页面
For instance with a 例如带有
<a href="same url?mime=textonly" target="_blank">
On the asp server, when the argument mime=textonly is detected, you change the mime type to text/plain 在ASP服务器上,当检测到参数mime = textonly时,将mime类型更改为text / plain
Perhaps I should have started with a comment to get more information but can you not: 也许我应该先发表评论以获取更多信息,但您不能:
Post back to a new window on click? 点击返回到新窗口?
<a target="_blank">
Though if the requirement is for the server to generate the new window, just append something like: <script>window.open('title'); </script>
尽管如果要求服务器生成新窗口,则只需附加如下内容:
<script>window.open('title'); </script>
<script>window.open('title'); </script>
at the end of the response and have the server populate that. <script>window.open('title'); </script>
放在响应末尾,并让服务器填充。
You could probably have the server code save the HTML to a file and output <script>window.open('urltothefile');</script>
. 您可能让服务器代码将HTML保存到文件中,然后输出
<script>window.open('urltothefile');</script>
。 Just make sure that you write a unique filename each time. 只要确保您每次都写一个唯一的文件名即可。
Alternatively, you could have the server code store all related information into a database and output <script>window.open('showResult.aspx?id=123');</script>
, where 123 is the id of the database record. 或者,您可以让服务器代码将所有相关信息存储到数据库中,然后输出
<script>window.open('showResult.aspx?id=123');</script>
,其中123是数据库记录的ID。 Then in showResult.aspx, have it generate the required HTML. 然后在showResult.aspx中,使其生成所需的HTML。
Another option is to output the HTML into a div with style="display: none"
, then have some javascript to assign the innerHTML to the newly opened window. 另一个选择是使用
style="display: none"
将HTML输出到div中,然后使用一些JavaScript来将innerHTML分配给新打开的窗口。 eg: 例如:
var w = window.open ('_blank');
w.document.body.innerHTML = document.getElementById("returnedHTML").innerHTML
One more possibility is to have a WebMethod. 还有一种可能性是拥有一个WebMethod。 I don't really remember how to declare one, but it is a server function that can be called from the client.
我真的不记得如何声明一个,但是它是可以从客户端调用的服务器功能。 Open the window via javascript, call the webmethod and place the result as the innerHTML of the newly opened window;
通过javascript打开窗口,调用web方法并将结果放置为新打开的窗口的innerHTML; Pretty much like the previous option.
非常类似于上一个选项。
All these are good but they don't work when you use UpdatePanel and partial rendering. 所有这些都很好,但是当您使用UpdatePanel和部分渲染时它们不起作用。 If that's the case, it's a whole different story.
如果真是这样,那就完全不一样了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.