locked
Image Url property in css file is not working (asp.net custom server control) RRS feed

  • Question

  • User-1779948929 posted

    Hi,

    I'm unable to refer the images from css file of custom control. I've changed the Build Action of the Image propery as Embedded Resource, Registered above the namespace of custom control. css file is linked in the custom control as below, all the properties in css file is working except the Image Url.

    [assembly: WebResource("CustomServerControl.CSS.DefaultStyleSheet.css", "text/css")]
    [assembly: WebResource("CustomServerControl.Images.brandbg.png", "image/png")]
    namespace CustomServerControl
    {
    public class ServerControl1 : CompositeControl
        {
         protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
       //Registering StyleSheet file
                string includeTemplate = "<link rel='stylesheet' text='text/css' href='{0}' />";
                string includeLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "CustomServerControl.CSS.DefaultStyleSheet.css");
                LiteralControl include = new LiteralControl(String.Format(includeTemplate, includeLocation));
                ((System.Web.UI.HtmlControls.HtmlHead)Page.Header).Controls.Add(include);
    //Registering javascript file
    Page.ClientScript.RegisterClientScriptResource(this.GetType(), "DropdownServerControl.JS.JScript1.js"); } } } //CSS #brandbutton ul .topbrd { background: transparent url('<%=WebResource("CustomServerControl.Images.brandbg.png")%>') no-repeat scroll left top; }

    The above Image URL property is not working. How to link the image url in css file?

    Thursday, April 5, 2012 11:06 AM

Answers

  • User3866881 posted

    I'm able to link css file as an embeded resource in project. But not able to use the images reffered in css file.

    Since you can embed your resource into project,I think you can directly use that resource in your project instead of using it in CSS file……because CSS file can only contain defined types in the form of string,but your resource isn't always type of that。

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 7, 2012 11:27 PM

All replies

  • User3866881 posted

    he above Image URL property is not working. How to link the image url in css file?

    What do you mean "Link the image url in css file"?What do you want to do?Want to link the css file as an embedded source into the proj or……?

    Reguards!

    Friday, April 6, 2012 9:53 PM
  • User-1779948929 posted

    Hi,

    I'm able to link css file as an embeded resource in project. But not able to use the images reffered in css file.

    Saturday, April 7, 2012 3:42 PM
  • User3866881 posted

    I'm able to link css file as an embeded resource in project. But not able to use the images reffered in css file.

    Since you can embed your resource into project,I think you can directly use that resource in your project instead of using it in CSS file……because CSS file can only contain defined types in the form of string,but your resource isn't always type of that。

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 7, 2012 11:27 PM