1

I am creating a visual web-part that has a few images, a CSS file and a java-script file, but i'm having issues. Can someone please tell me what I am missing or doing wrong?

I have added the files to my project and made them "embedded resources" via the property window. I have also added the following to my "AssemblyInfo.cs" file.

//Embedded Resources for this Assembly are the following
[assembly: System.Web.UI.WebResource("LibrarySlider.SliderWebPart.style.css", "text/css")]
[assembly: System.Web.UI.WebResource("LibrarySlider.SliderWebPart.slider.js", "text/javascript")]
[assembly: System.Web.UI.WebResource("LibrarySlider.SliderWebPart.arrows-2.png", "image/jpg")]
[assembly: System.Web.UI.WebResource("LibrarySlider.SliderWebPart.arrows-3.png", "image/jpg")]
[assembly: System.Web.UI.WebResource("LibrarySlider.SliderWebPart.arrows-4.png", "image/jpg")]
[assembly: System.Web.UI.WebResource("LibrarySlider.SliderWebPart.arrows.png", "image/jpg")]

in my ascx.cs file i have the following methods:

  1. createChildControls
  2. Render(HtmlTextWriter writer)
  3. OnPreRender(EventArgs e)

in my prerender i have the folowing code:

string styleSheetUrl = Page.ClientScript.GetWebResourceUrl(this.Parent.GetType(), "LibrarySlider.SliderWebPart.style.css");
string srptLoc = Page.ClientScript.GetWebResourceUrl(this.GetType(), "LibrarySlider.SliderWebPart.slider.js");

My web-parts Render(HtmlTextWriter writer) content is displaying but when i view he source i don't see the CSS or java-script file linking in. And secondly how would i get the images?

Thanks in advanced for any help!!

2 Answers 2

0

Have you tried using modules instead of embedded resources? I have used them in the past to provide images and scripts without any issues.

2
2

You can add the layouts mapped folder to your project and keep javascript and css files there.You can then use ScriptLink class to register the js and CssRegistration class to register the css in the Page_Load method of the webpart. Following is the example:

private const string script = "/_layouts/JQuery/JS/jquery.min.js";
ScriptLink.Register(Page, script , false);

private const string jqueryCss= "/_layouts/CSS/jquery-ui.css";
CssRegistration.Register(jqueryCss);

SOURCE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.