How to link imagebutton to a visual web developer url

I was wondering if it is possible to link an image button to a website? And How? I use web forms in a visual web developer. thank.

+3
source share
3 answers

You can try this

<asp:ImageButton runat="server" ID="ImageButton1" PostBackUrl="http://www.google.com" /> 
+4
source

Clicking on ImageButton will trigger a PostBack on the server, where you can handle the 'Click' event. From there you can redirect to 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 client-side redirects using the OnClientClick property for ImageButton:

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

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

<a href="http://google.com">
    <img src="/someimage.jpg" alt="" />
</a>
+1
source
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images1.png" 
            onclick="ImageButton1_Click" />

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

hyperlink control

 <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default3.aspx" ImageUrl="~/images1.png">HyperLink</asp:HyperLink>
+1

Source: https://habr.com/ru/post/1694915/


All Articles