views:

57

answers:

4

I have an <asp:Image> element and a text caption, surrounded by an <a> element. I need the link to run a method when clicked, changing the ImageUrl property of another <asp:Image> element.

I'm a total noob with ASP.NET (Clearly.)
Can anyone explain this process to me?

A: 

Is the Method on the Server?

Then you need to use the ASP.NET Link Control. You can hook up to the OnClick event on the Link Control.

David Basarab
I can't find the Link control anywhere in my toolbox. It is not a mobile web page. Is the Link control not available for reguar ASP.NET web forms?
Giffyguy
+3  A: 

I think the ImageButton control will do it for you: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.imagebutton.aspx

It fires a postback, giving you all the events you expect.

Matt Sherman
That would be perfect, as long as it doesn't look retarded. I don't want any vusual "button" movements or animations - like when the button is depressed.
Giffyguy
No, it doesn't behave visually like an HTML button. Just an image.
Matt Sherman
+5  A: 

Is changing the image the only thing you're doing? If so, you should probably keep this all in javascript, or least try to use javascript first and only postback if javascript is disabled. Server events are bad for performance.

Joel Coehoorn
This is probably the best answer, and it is definitely a very simple task that Javascript can handle in a heartbeat. But I'm not so great with Javascript or ASP.NET web forms. Can you give me a code example, showing what elements to use and how to link them to the Javascript?
Giffyguy
It's as simple as `document.getElementById('myimageID').src="newSource.jpg";`
Joel Coehoorn
yes, good point. if it's simply a client-side change, javascript will do it.
Matt Sherman
+2  A: 

An imagebutton will be your best bet. It is basically a button but the look of simply an image. There is no depressing or any movement with this control.

JonH
I see. +1 for the good info.
Giffyguy