Search code examples
htmlasp.netimageurl

loading dynamic photo using ASP.net with IMAGE.ImageUrl


I am using asp.net for a website and i am using nested master page. i want to load dynamic a picture from the nested master page.

the html code in the nested master page is:

<a runat="server">
        <asp:Image id="usrimg" src="" alt="Image Not Found" runat="server" />
</a>

the C# code is:

protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
        var u = Session["user"] as Worker;
        String s = "/images/" + u.UserName + ".jpg";

        usrimg.ImageUrl = s;
    }
}

note that the path is correct( i debug the code behind) but always the source in the inspect is unknown.

this is the result :

<img id="userphoto_ContentPlaceHolder1_usrimg" src="" alt="Image Not Found">

Solution

  • i solve it by using :

    usrimg.Attributes["src"] = s;