ASP.NET在运行时创建HTML时打开新窗口 [英] ASP.NET Opening New Window with HTML Created During Run-Time

查看:68
本文介绍了ASP.NET在运行时创建HTML时打开新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有gridview的aspx(分页和排序),我想在新页面中显示它 - 典型的打印预览情况。


最初,GridView是简单的。 (没有分页)我写了一个JavaScript,它通过使用< span>来转移来自其他控件的数据(包含用于填充gridview的参数)。带有特定标题属性的标签。我使用.innerHTML属性来查找我感兴趣的值,并使用.innerHTML将GridView(作为HTML表格)复制到新创建的页面中。


现在我决定了切换到更面向服务器的解决方案 - 我想通过运行在服务器上的c#代码中的控件,并在运行时构建一个新的HTML(类似于js但更容易实现)。


我的问题是 - 如何处理新生成的HTML代码?我只能使用Response.Redirect转到现有页面,当我使用Response.Write时,我会写入同一个窗口。我想创建像JS一样的行为(打开一个新窗口),但实际的HTML代码来自服务器。


有关正确方法的任何建议吗?


谢谢,

Frankie

I have an aspx with a gridview (paged and sorted) and I want to display it in a new page - typical Print Preview situation.

Initially the GridView was "simple" (no paging) and I wrote a JavaScript that transfered data from other controls (containing parameters used to populate the gridview) by using <span> tags with a specific ''title'' attribute. I used the .innerHTML property to find the values I was interested in, and also used .innerHTML to copy the GridView (as HTML Table) into the newly created page.

Now I decided to switch to a more server oriented solution - I want to go through the controls in c# code running on the server and build a new HTML in runtime (similar to the js but easier to implement).

My problem is - what do I do with the new generated HTML code? I can only use Response.Redirect to go to an existing page and when I use Response.Write I write to the same window. I want to create the behavior like I had with JS (open a new window) but have the actual HTML code come from the server.

Any suggestions on the right way to achieve that?

Thanks,
Frankie

推荐答案

您是否尝试使用页面加载事件来触发JS中的onload事件? Registerstartupscript可能适合您。 HTH。
Have you tried using page load event to fire an onload event in JS? Registerstartupscript may work for you. HTH.



您是否尝试过使用页面加载事件来触发JS中的onload事件? Registerstartupscript可能适合您。 HTH。
Have you tried using page load event to fire an onload event in JS? Registerstartupscript may work for you. HTH.



嘿kenobewan,


感谢您的回复,但我不明白您的建议。


假设我的页面是Report.aspx。我想导航到一个没有url的页面,因为没有aspx / html文件,只是我在运行时创建的字符串,就像在Button_Click代码中一样,一旦用户点击了打印按钮。


form_load或onload事件在哪里进入?

Hey kenobewan,

Thanks for the reply but I don''t understand your suggestion.

Let''s say I have my page Report.aspx. And I want to navigate to a page that doesn''t have a url since there''s no aspx/html file, just a string I created in run-time, like in the Button_Click code, fired once the user clicked on the Print button.

Where do the form_load or onload events come into this?



I有一个带有gridview的aspx(分页和排序),我想在新页面中显示它 - 典型的打印预览情况。


最初,GridView是简单的。 (没有分页)我写了一个JavaScript,它通过使用< span>来转移来自其他控件的数据(包含用于填充gridview的参数)。带有特定标题属性的标签。我使用.innerHTML属性来查找我感兴趣的值,并使用.innerHTML将GridView(作为HTML表格)复制到新创建的页面中。


现在我决定了切换到更面向服务器的解决方案 - 我想通过运行在服务器上的c#代码中的控件,并在运行时构建一个新的HTML(类似于js但更容易实现)。


我的问题是 - 如何处理新生成的HTML代码?我只能使用Response.Redirect转到现有页面,当我使用Response.Write时,我会写入同一个窗口。我想创建像JS一样的行为(打开一个新窗口),但实际的HTML代码来自服务器。


有关正确方法的任何建议吗?


谢谢,

Frankie
I have an aspx with a gridview (paged and sorted) and I want to display it in a new page - typical Print Preview situation.

Initially the GridView was "simple" (no paging) and I wrote a JavaScript that transfered data from other controls (containing parameters used to populate the gridview) by using <span> tags with a specific ''title'' attribute. I used the .innerHTML property to find the values I was interested in, and also used .innerHTML to copy the GridView (as HTML Table) into the newly created page.

Now I decided to switch to a more server oriented solution - I want to go through the controls in c# code running on the server and build a new HTML in runtime (similar to the js but easier to implement).

My problem is - what do I do with the new generated HTML code? I can only use Response.Redirect to go to an existing page and when I use Response.Write I write to the same window. I want to create the behavior like I had with JS (open a new window) but have the actual HTML code come from the server.

Any suggestions on the right way to achieve that?

Thanks,
Frankie



嗨弗兰基,


你要让它变得比它需要的更复杂。

你不需要专门为打印目的创建HTML代码。

你的进展真的很复杂(你必须创建一个临时的网页,以便网页浏览器可以加载它......然后你必须管理这些临时资源,这样你的网络服务器就不会被填满报告......这是一个真正的痛苦和很多工作......你不需要这样做)


你可以有一个按钮打印预览,单击时将取消GridView上的分页(格式为GridView和用于打印的网页)。当你这样做时,你可以简单地隐藏任何你不想要打印的东西,只显示应该是什么。


另外,看看用CSS来帮助你打印格式。


-Frinny

Hi Frankie,

You''re making this more complicated than it needs to be.
You don''t need to create HTML code specifically for printing purposes.
The way your going is really complicated (you''d have to create a temporary web page so that the web browser could load it...then you have to manage these temporary resources so that your web server''s not filled up with reports...it''s a real pain and a lot of work...you don''t need to do this)

You could have a button "Print Preview", which when clicked would take away the paging on your GridView (format GridView and the web page for printing purposes). When you do this, you could simply hide anything that you don''t want printed and show only what should be.

Also, look into using CSS to help with your print formatting.

-Frinny


这篇关于ASP.NET在运行时创建HTML时打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆