How to access non-asp <img> tag from code behind?

We're working on a big project and we're stuck a bit here. I need to access the <img>'s from an .ASPX from the code-behind on the PageLoad() to assign the right image (attrib src) depending on the value we just collected from the DB from an SQL Query.

We can't use the runat="server" attribute to see it server side because we got a bunch of jQuery using the img name tag to work with.

I'm sure there's a way to access and modify the src attribute of the images from the code behind view?

Upvotes: 2

Views: 3221

Answers (3)

rick schott
rick schott

Reputation: 21112

To set the src attribute you will have to re-render the control or manipulate by emitting JavaScript.

Upvotes: 0

Wouter de Kort
Wouter de Kort

Reputation: 39898

You can use the ClientIdMode=Static property on your image tag. That way you can add the runat=server attribute and you can still access the image tag from your jquery.

Check the following documentation for more info.

Upvotes: 1

Oded
Oded

Reputation: 499352

You can use a Literal control to output the image element.

You can access the value of the literal to extract (parse out) any information from it and re-write it.

Upvotes: 2

Related Questions