user616076
user616076

Reputation: 4001

How to update Html control without runat="server"

I have an Html image which I need to update dynamically but without runat="server" my code behind cannot see it.

<img name="MDI" id="detailimg" src="" alt="blankimage.jpg" />

I can access it using Page.Request.Form["MDI"]; but not update it

I need to load the src image at run time so can someone please tell me how I can update the control in my code.

Upvotes: 0

Views: 1838

Answers (3)

Murali Murugesan
Murali Murugesan

Reputation: 22619

Do with inline syntax like below

<img name="MDI" id="detailimg" src="<%= getImageSource() %>" alt="blankimage.jpg" />

In codebehind

public string getImageSource()
{
   return "urlpath/img.jpeg";
}

More about Inline Syntax

Upvotes: 4

Kamran Sadin
Kamran Sadin

Reputation: 921

as you know if you want to access an element/control from code behind,you should set runat="server" but there is 2 other ways to set properties from code behind

  1. use inline syntax as other guys shows (<%= YourVoidToGetImgSrc %>
  2. use Ajax and get value from code behind in your html page.

Upvotes: 0

MichaC
MichaC

Reputation: 13380

If you want to update via code behind, you have to set runat="server"

If inline is fine, use src="<%= something%>

Otherwise use javascript for example

Upvotes: 0

Related Questions