最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Open a new window with asp.net - Stack Overflow

programmeradmin1浏览0评论

Im new into that asp thing, but here goes.

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.

Im new into that asp thing, but here goes.

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.

Share Improve this question edited Aug 21, 2012 at 8:56 000 3,9504 gold badges27 silver badges39 bronze badges asked Jan 3, 2009 at 21:14 CruelIOCruelIO 18.6k16 gold badges45 silver badges60 bronze badges
Add a ment  | 

7 Answers 7

Reset to default 3

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

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.

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./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

You can use the ImageButton's OnClientClick property:

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

But this popup window will not be modal.

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

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

It might be worth pointing to a two relevant entries in the excellent EFNet's #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 Lightbox or 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.

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

And it works perfectly

发布评论

评论列表(0)

  1. 暂无评论