zkanoca
zkanoca

Reputation: 9928

asp:Image does not show the image

I have this code. This code is a part of my menu items:

<li class="" id="fifth-li">
    <ul style="visibility: hidden; display: none;" id="fifth-ul">
        <li><asp:HyperLink ID="hpl_undergraduate" runat="server"></asp:HyperLink></li>
        <li><asp:HyperLink ID="hpl_graduate" runat="server"></asp:HyperLink></li>  
    </ul>
        <asp:HyperLink ID="hpl_lessons" runat="server">
        <asp:Image ID="img_lessons"  runat="server" />
        <strong></strong>
        <em id="em_lessons" runat="server"></em>
        </asp:HyperLink>
</li> 

And this is a part of my .cs code file:

em_lessons.InnerHtml = lang["MENU_LESSONS"];
hpl_lessons.Text = lang["MENU_LESSONS"];
hpl_undergraduate.Text = lang["MENU_UNDERGRADUATE"];
hpl_graduate.Text = lang["MENU_GRADUATE"];

hpl_lessons.NavigateUrl = "lessons.html";
hpl_undergraduate.NavigateUrl = "lessons-801.html";
hpl_graduate.NavigateUrl = "lesson-802.html";
img_lessons.ImageUrl = "images/lessons.png"; //Here the image url is defined.

This code is for my web page's menu. There are a few more items like this. I add an image to the img_lessons object on the codebehind. But after running the page I get this code:

<li class="" id="fifth-li">
    <ul style="visibility: hidden; display: none;" id="fifth-ul">
        <li>
            <a id="MainContent_hpl_undergraduate" href="lesson-801.html">
                Undergraduate
            </a>
        </li>
        <li>
            <a id="MainContent_hpl_graduate" href="lesson-802.html">
                Graduate
            </a>
        </li>  
    </ul>
    <a id="MainContent_hpl_lessons" href="lessons.html">
        Lessons
    </a>
</li>

I was thinking that if I pull out img_lessons between <asp:HyperLink></asp:HyperLink>, the image would have been shown. But no way. I have changed the codes a bit to be cleaner.

The point is not about the image path, is about some programmatic incompetence/inconvenience. Because I do not see a <img id="MainContent_img_lessons" ... /> code on the browser's code view.

As you can see my image does not look. What do you think?

Regards.

Upvotes: 0

Views: 415

Answers (2)

Tieson T.
Tieson T.

Reputation: 21239

When you do this:

hpl_lessons.Text = lang["MENU_LESSONS"];

you are wiping out any and all markup from the inside of the hyperlink.

EDIT: Since it looks like you already have a <em> tag that you have made a server tag, this line:

em_lessons.InnerHtml = lang["MENU_LESSONS"];

should already be setting viewable text, so, really, you should only have to remove the line mentioned above.

Upvotes: 2

KaraokeStu
KaraokeStu

Reputation: 768

You are clearing the hyperlink innerHTML when you are setting the .Text to lang["MENU_LESSONS"]

What you would need to do is change your markup as follows:

<asp:HyperLink ID="hpl_lessons" runat="server">
    <asp:Image ID="img_lessons"  runat="server" />
    <strong><asp:Literal ID="lit_lessons"/></strong>
    <em id="em_lessons" runat="server"></em>
</asp:HyperLink>

And then change your code so that it reads

lit_lessons.Text = lang["MENU_LESSONS"];

Upvotes: 1

Related Questions