C# 用asp.net打开一个新窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/409846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 02:15:52  来源:igfitidea点击:

Open a new window with asp.net

c#javascriptasp.netajaxmodal-dialog

提问by CruelIO

Im new into that asp.net thing, but here goes.

我是那个 asp.net 的新手,但这里是。

I got at ImageButton, and when its clicked i want the image displayed in another window. If I can avoid using ajax i would like to do that. If possible would like to make the window modal, but still avoid ajax, since Im not ready to mix more technolgies yet.

我得到了 ImageButton,当它被点击时,我希望图像显示在另一个窗口中。如果我可以避免使用ajax,我想这样做。如果可能的话,我想使窗口模式化,但仍然避免使用 ajax,因为我还没有准备好混合更多的技术。

采纳答案by Germstorm

IMHO the best practice to show a picture is in the same page on the top of the content. I personally use Lightbox. You can find the documentation on their page, so it should be easy for you to integrate their JavaScript code.

恕我直言,显示图片的最佳做法是在内容顶部的同一页面中。我个人使用Lightbox。您可以在他们的页面上找到文档,因此集成他们的 JavaScript 代码应该很容易。

回答by Filip Ekberg

Somewhat like this:

有点像这样:

<asp:ImageButton ID="imbJoin" CssClass="btn-find" AlternateText="Find" ToolTip="Find" runat="server" ImageUrl="~/library/btn-find.gif" onClick="javascript:popUp("ServicesLocator.aspx")" />

Resource: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22832169.html

资源:http: //www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22832169.html

Using the ImageButton you need to use a JavaScript to open it in a new window. You can also look into the OnClientClick-event

使用 ImageButton 您需要使用 JavaScript 在新窗口中打开它。您还可以查看 OnClientClick 事件

回答by M4N

You can use the ImageButton's OnClientClick property:

您可以使用 ImageButton 的 OnClientClick 属性:

<asp:ImageButton ... OnClientClick="javascript:window.open('url_to_image');" >

But this popup window will not be modal.

但是这个弹出窗口不会是模态的。

回答by Gavin Miller

The following javascript will do what you're looking for:

以下 javascript 将执行您正在寻找的操作:

window.open('page.html','WindowTitle','width=400,height=200')

回答by Jon Skeet

The existing answers with JavaScript are fine, but just to suggest an alternative - could you use a HyperLink(with an ImageUrlset so you still get an image) and set its Targetproperty instead?

JavaScript 的现有答案很好,但只是建议一个替代方案 - 您可以使用超链接(设置ImageUrl以便您仍然获得图像)并设置其Target属性吗?

回答by Bj?rn

It might be worth pointing to a two relevant entries in the excellent EFNet's #javascript FAQ:

可能值得指出优秀EFNet 的 #javascript FAQ中的两个相关条目:

  1. Correct Use of Popups- yay accessibility!
  2. How do I make a popup window the same size as my image?
  3. How do I create a custom 'OK' dialog or something similar?- modal windows are not that useful and something like the suggested Lightboxor similar scripts would be better "modal" options
  4. Correct Use of Links- this one being only partly on-topic but the previous answers use of the "javascript:" pseudo protocol made it necessary: it is never required nor useful in a web page that should work across browsers. After all, JavaScript is the default (and only) scripting language.
  1. 正确使用弹出窗口- 是的可访问性!
  2. 如何使弹出窗口与我的图像大小相同?
  3. 如何创建自定义的“确定”对话框或类似的东西?- 模态窗口不是那么有用,建议的灯箱或类似脚本之类的东西会是更好的“模态”选项
  4. 正确使用链接- 这只是部分主题,但之前使用“javascript:”伪协议的答案使其成为必要:它在应跨浏览器工作的网页中从不需要也没有用。毕竟,JavaScript 是默认的(也是唯一的)脚本语言。

回答by CruelIO

Thank you for all the answers! I ended up using lightbox I found this example http://neutrongenious.wordpress.com/2007/09/08/lightbox-for-asp-net-2-0/

谢谢大家的回答!我最终使用了灯箱我发现了这个例子 http://neutrongenious.wordpress.com/2007/09/08/lightbox-for-asp-net-2-0/

And it works perfectly

它完美地工作