Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I need to display image from back-end code.

Here my code:
Events.aspx.cs:
C#
switch (sExtension)
{
    case "docx":
        SLogo = "../assets/images/Events/word_logo.jpg";
        break;
    case "doc":
        SLogo = "../assets/images/Events/word_logo.jpg";
        break;
    case "ppt":
        SLogo = "../assets/images/Events/ppt_logo";
        break;
    case "jpg":
        SLogo = "../assets/images/Events/jpg_logo";
        break;
    case "pdf":
        SLogo = "../assets/images/Events/pdf_logo";
        break;
}


Events.aspx
XML
<img id="logo_img" src="" alt="" />


But in Evets.aspx.cs, I can't access this image control.

I need to access this as, logo_img.src = sLogo;
Posted
v3

1 solution

Use Asp.Net Image[^] Control.
XML
<asp:Image ID="logo_img" runat="server" AlternateText="SomeAlternateTextForImage"></asp:Image>

Now do like below in aspx.cs page.
C#
logo_img.ImageUrl = sLogo;
 
Share this answer
 
v2
Comments
lalitha19 18-Nov-13 9:33am    
No in backend,the id name is not accepting. that is if i type logo_img,it doesn't show its properties
It is very strange. Have you added the Image control on aspx page as I said?
lalitha19 26-Nov-13 7:30am    
yes.. I added img control as you said. but it doesn't add in Events.aspx.designer.cs file.
Then delete this control. Now add one Image control from the ToolBox. Then build the project.

After that try to access it from code behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900