Question

Im new into that asp.net 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.

Was it helpful?

Solution

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.

OTHER TIPS

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?

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

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.com/2007/09/08/lightbox-for-asp-net-2-0/

And it works perfectly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top