How to set html img src from code behind

Posted by donraza007-15388 under ASP.NET on 6/13/2012 | Points: 10 | Views : 21450 | Status : [Member] | Replies : 3
I have a html image in my asp.net page. Intially it is null. Image will be set dynamically from server side means from code behind. How is it possible.




Responses

Posted by: Santhi on: 6/13/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
aspx page:
<img alt="" src="" runat="server" id="imageid" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

Code behind:
protected void Button1_Click(object sender, EventArgs e)
{
imageid.Src = "4th Floor- Apr-12 Model (1).jpg";

}

Thanks & Regards,
Santhi .V

donraza007-15388, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: donraza007-15388 on: 6/13/2012 [Member] Starter | Points: 25

Up
0
Down
It works fine but i have to change the img src from java script also after page load which is not working. Any other way without writing runat="server"

donraza007-15388, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhiram on: 6/14/2012 [Member] Starter | Points: 25

Up
0
Down
<img src="blank.jpg" id="image" alt="just nothing">

<script type="text/javascript">
document.getElementById('image').src = "yourpicture.jpg";
</script>

donraza007-15388, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response