I am using Visual Studio 2005 Express and C# - I have a HyperLink and an ImageButton - the HyperLink opens it's specified url in a new window using Target="_blank" -but- the ImageButton does not allow Target="_blank" and opens it's specified url
in the same window. How can I get the ImageButton to open a NEW window.
ImageButton is nothing but a button, so you can't simply open a URL with it! You are defeating the purpose if you want to use a button to open a URL in a new window.
if you want to open a link , hyper link is for you, Now why you need imagebutton for that, any way if you want to open a new window , when somebody clicks on the image button , it is possible
I know this executed (I see it in the debugger) -but- it seems to be ignored? the page that executed this command just re-displays and the intended link http://www.nfl.com/news never shows... The HyperLink for the same link opens in a new browser window.
I know I don't need both the HyperLink and the ImageButton - - - the intention is that I have a picture and a "Read full story" HyperLink - I wanted to have the ImageButton also link to the same location...
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" Height="115px" ImageUrl="http://images.nfl.com/photos/img9714526.jpg" Width="114px" OnClick="ImageButton2_Click" PostBackUrl="http://www.nfl.com/news" />;
..... this one opens the location in the same window...
I know this can't be that hard -but- I am very new to this web stufffff. :):)
Have you had a look at my control? You don't even need to think of Javascript when you want to open a new window, a simple call to a method and a pop up window is opened for you!!
Bilal - Sorry about your control, I have so many things on my plate - just didn't want to learn another. I have it bookmarked and if I ever need a popup - I'll check it out. I never open windows unless the visitor clicks. :)
Paul44
Member
131 Points
50 Posts
URL in new window
Oct 12, 2006 04:34 AM|LINK
I am using Visual Studio 2005 Express and C# - I have a HyperLink and an ImageButton - the HyperLink opens it's specified url in a new window using Target="_blank" -but- the ImageButton does not allow Target="_blank" and opens it's specified url in the same window. How can I get the ImageButton to open a NEW window.
Thanks,
Paul
haidar_bilal
All-Star
45609 Points
8730 Posts
MVP
Re: URL in new window
Oct 12, 2006 05:19 AM|LINK
ImageButton is nothing but a button, so you can't simply open a URL with it! You are defeating the purpose if you want to use a button to open a URL in a new window.
What you can do though, is create an event handler for the button and use my free control: http://bhaidar.net/cs/files/5/january_2006/entry59.aspx
This control allows you to popup a new window from inside code-behind.
Hope this helps,
Regards
Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB
sreejukg
All-Star
28187 Points
4214 Posts
Re: URL in new window
Oct 12, 2006 06:32 AM|LINK
if you want to open a link , hyper link is for you, Now why you need imagebutton for that, any way if you want to open a new window , when somebody clicks on the image button , it is possible
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Write("<script>window.open('page.html','newwin');</script>");
}
My Blog
Paul44
Member
131 Points
50 Posts
Re: URL in new window
Oct 12, 2006 02:23 PM|LINK
I tried the solution:
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Write("<script>window.open('http://www.nfl.com/news','newwin');</script>");
}
I know this executed (I see it in the debugger) -but- it seems to be ignored? the page that executed this command just re-displays and the intended link http://www.nfl.com/news never shows... The HyperLink for the same link opens in a new browser window.
I know I don't need both the HyperLink and the ImageButton - - - the intention is that I have a picture and a "Read full story" HyperLink - I wanted to have the ImageButton also link to the same location...
Am I missing something in the script area?
I tried using both:
private void ImageButton1_Click(object sender, ImageClickEventArgs e) -and-
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
and I tried both:
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" Height="115px" ImageUrl="http://images.nfl.com/photos/img9714526.jpg" Width="114px" OnClick="ImageButton2_Click" />
-and-
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" Height="115px" ImageUrl="http://images.nfl.com/photos/img9714526.jpg" Width="114px" OnClick="ImageButton2_Click" PostBackUrl="http://www.nfl.com/news" />;
..... this one opens the location in the same window...
I know this can't be that hard -but- I am very new to this web stufffff. :):)
Thanks for your help,
Paul
haidar_bilal
All-Star
45609 Points
8730 Posts
MVP
Re: URL in new window
Oct 12, 2006 06:55 PM|LINK
Have you had a look at my control? You don't even need to think of Javascript when you want to open a new window, a simple call to a method and a pop up window is opened for you!!
Regards
Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB
midwestern_d...
Member
561 Points
110 Posts
Re: URL in new window
Oct 12, 2006 07:28 PM|LINK
try wrapping ahyper link around and image
<asp:hyperlink id='me' runat=server><img source=abc.gif /> </asp:hyperlink>
midwestern_d...
Member
561 Points
110 Posts
Re: URL in new window
Oct 12, 2006 07:46 PM|LINK
Something like this
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.microsoft.com" Target="_me">
<img >
</asp:HyperLink>
Paul44
Member
131 Points
50 Posts
Re: URL in new window
Oct 13, 2006 05:07 AM|LINK
Thanks - here is what I worked for me:
<asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="http://www.microsoft.com" Target="_me" Height="94px" Width="79px" ImageUrl="http://i2.microsoft.com/h/all/i/ms_masthead_10x7a_ltr.jpg"></asp:HyperLink>
Bilal - Sorry about your control, I have so many things on my plate - just didn't want to learn another. I have it bookmarked and if I ever need a popup - I'll check it out. I never open windows unless the visitor clicks. :)
Thanks all
mcoxall
Member
2 Points
2 Posts
Re: URL in new window
Aug 21, 2007 03:07 PM|LINK
in the event add the following
Page.Form.Target = "_blank"