173901
173901

Reputation: 709

what am i missing to use embedded resources?

I am using Asp.net with c# in Visual studios 2012. I added the images i need into the solution by

I went into the project properties assembly info.cs and added references to my resources.

[assembly: WebResource("FIMS_Courses.Images.FIMSNext.gif", "image/gif")]
[assembly: WebResource("FIMS_Courses.Images.FIMSPrevious.gif", "image/gif")]
[assembly: WebResource("FIMS_Courses.Images.FIMSCourselist.gif", "image/gif")]
[assembly: WebResource("FIMS_Courses.Images.FIMStopofpage.gif", "image/gif")]

now i am trying to access them. Inside my asp potion of my program i select them by typing imageUrl= and then intellesense lets me choose the path; This is my code:

<asp:ImageButton ID="PreviousListLink" ImageUrl="~/Images/FIMSCourselist.gif" CssClass="floatleft" runat="server"/> <asp:ImageButton ID="PreviousButtonTop" ImageUrl="~/Images/FIMSPrevious.gif" runat="server"/> &nbsp; <asp:ImageButton  ID="NextButtonTop" ImageUrl="~/Images/FIMSNext.gif" runat="server" />

<h4><asp:Label ID="CourseNumber" Text="####" runat="server"/> &nbsp; <asp:Label ID="CourseTitle" Text="This is a course Title" runat="server" /></h4>

<asp:Label id="Desc" text="Course Description" />
<a href="#TopOfPage"class="floatleft"><asp:Image ID="TopOfPageButton" ImageUrl="~/Images/FIMStopofpage.gif" runat="server" /></a>   <asp:ImageButton ID="PreviousButtonBottom" ImageUrl="" runat="server" />&nbsp;<asp:ImageButton ID="NextButtonBottom" ImageUrl=""  runat="server"/>

and when i give it a test run i get nothing showing up. no images what so ever. No images Loaded

am i missing some crucial steps to access embedded resources?

Upvotes: 3

Views: 782

Answers (1)

Rick S
Rick S

Reputation: 6586

You need to reference your embedded resources using the code-behind.

Example:

string topOfPageImageUrl  = Page.ClientScript.GetWebResourceUrl(this.GetType(),
                       "FIMS_Courses.Images.FIMStopofpage.gif");
TopOfPageButton.ImageUrl = topOfPageImageUrl;

Upvotes: 1

Related Questions