Accessing Resources from User Controls

Nov 13, 2009 at 5:59 PM

I'm trying to create a web part that includes a user control that needs access to a couple images and a CSS file for formatting. I used these instructions to configure WSPBuilder to allow me to build the user control, and read this article about including resources for my web part. However, trying to access the resources from the wrapped user control is causing some errors. If the resources are embedded and the Page.ClientScript.GetWebResourceUrl() method is used from the user control, the WebResource.axd URL is returned, neither the images nor the CSS file actually loads. If I try using a linked resource, and accessing it with the SPWebPartManager.GetClassResourcePath() method, I get an error stating "A Web Part or Web Form Control on this Page cannot be displayed or imported. The type is not registered as safe."

As a workaround, I can create properties in my User Control to store the appropriate URLs, then from the web part class that calls Page.LoadControl(), I can execute the above methods successfully, and pass the returned results to the User Control.

Is this the appropriate path to take, or is there some configuration issue that I've missed?

Thanks,

Evan