3

I was wondering, is it possible to link an imagebutton to a website? and how? Im using a web forms in visual web developer. thanks.

AAA
  • 811
  • 2
  • 7
  • 7

3 Answers3

4

You can try this

<asp:ImageButton runat="server" ID="ImageButton1" PostBackUrl="http://www.google.com" /> 
sejal patel
  • 262
  • 2
  • 4
  • 12
  • one more thing, also regarding the imagebutton problem, i have set the postbackurl to another asp page. but when i run it, there was error. Compiler Error Message: CS1061: 'ASP.login_aspx' does not contain a definition for 'ImageButton2_Click' and no extension method 'ImageButton2_Click' accepting a first argument of type 'ASP.login_aspx' could be found (are you missing a using directive or an assembly reference?) what should i do?sorry, im really new at this. – AAA Aug 08 '12 at 07:46
1

Clicking on an ImageButton will cause a PostBack to the server where you can handle the 'Click' event. From there you can redirect wherever you want.

<asp:ImageButton runat="server" ID="ImageButton1" OnClick="ImageButton1_Click" ...

protected void ImageButton1_Click(object sender, EventArgs e) {
    Response.Redirect("http://www.google.com");
}

You can also perform redirects from the client side using the OnClientClick property of the ImageButton:

<asp:ImageButton runat="server" ID="ImageButton1" OnClientClick="window.location.href = 'http://www.google.com';" ...

Or, you can avoid all this complexity by wrapping a standard <img /> element or ASP.NET Image with a link:

<a href="http://google.com">
    <img src="/someimage.jpg" alt="" />
</a>
Derek Hunziker
  • 12,996
  • 4
  • 57
  • 105
1
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images1.png" 
            onclick="ImageButton1_Click" />

 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("default1.aspx");
    }

OR use hyperlink control

 <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default3.aspx" ImageUrl="~/images1.png">HyperLink</asp:HyperLink>
Satinder singh
  • 10,100
  • 16
  • 60
  • 102