Reputation: 3896
I think I've been standing in front of the computer today because I can't think of the most basic thing to do with an asp:imageButton.
I just want to have an ImageButton that goes to an external link when clicked. I don't want to use OnClick and CodeBehind for the redirection. Is there a way to just set it in the .aspx?
asp:HyperLink or LinkButton with Image tag inside will work too but I don't want the image surrounded with the blue hyperlink border.
Whats the best way to do it?
Upvotes: 0
Views: 3772
Reputation: 3634
If you do not want to use CodeBehind, is there any reason to use the server side control? Why not use the HTML anchor (<a>) tag and put an <img> tag inside it. That way you can set the href to whatever link you want to take the user to.
If you still want to use an ImageButton, set the OnClientClick atribute to call a JavaScript method. Alternately, you can set the ClientIdMode to "Static" and use javascript / jquery to add an event handler for the onclick event.
Upvotes: 4
Reputation: 1366
Instead of using OnClick you can use javascript.
<script type="text/javascript">
function redirectTo()
{
window.location = "YOUR URL";
}
</script>
and then:
<asp:imageButton ... OnClientClick="redirectTo();" ... />
Upvotes: 2