.Net 2.0 - WebResource attribute with css file

Discussion in 'ASP .Net Building Controls' started by Vesa Juvonen, Nov 11, 2005.

  1. Vesa Juvonen

    Vesa Juvonen Guest

    Hi,

    I'm developing a custom control using VS2005. The control has embedded
    resources with it (js, images and css) and when control is rendered to page,
    it uses the GetWebResourceUrl funtion to get correct address for the
    resources (resources are streamed directly from assembly using
    WebResource.axd).



    Everything works well with images and javascript files, but for some reason
    the css files are not streamed correctly. Is this a restrictions in the
    HttpHandler, or something else?





    In this case the web site level Themes or css files are not an option (these
    are not suitable for reusable control development). Of course the css
    attributes could be applied to each html element individually, but this
    would cause repeating the style attributes for each element, which would
    cause the page sizes to increase unnecessarely.





    Sample code to demostrate

    -----------------------------------------

    -- Code snipped for the Images - Works well --



    Embedded image in assembly named as foo.gif

    <Assembly: WebResource("foo.gif", "image/gif")> - As a assembly attribute

    Me.Page.ClientScript.GetWebResourceUrl Me.GetType, "foo.gif") - for img src



    Let's put the link address of image (from client side page) to browser
    address box: We can see the image from the assembly.





    -- Code snipped for the Images - does not work --

    Embedded css in assembly named as BWVerticalMenu.css

    <Assembly: WebResource("foo.css", "text/css")>

    Me.Page.ClientScript.GetWebResourceUrl Me.GetType, "foo.css") - for htmllink
    href property



    Let's put the link address of css file (from client side page) to browser
    address box: We get empty html page... which was not expected.We would like
    to have the css file as in the image case.





    --

    There's an excellent article concerning this functionality in te MSDN
    including sample files:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/webresource.asp



    However the samples provided in this article don't work with the released
    version of VS2005 (built on earlier version), due minor changes in class
    members. f.ex the LinkedStyleSheet is no more accessable from the controls
    in the page, since the function has been swithed to protected. Well. in
    sense ot current problem, this is not the issues, since we can by pass this
    problem using Header.Controls collection and HtmlLink class.

    --





    Thanks in Advance

    - Vsku
     
    Vesa Juvonen, Nov 11, 2005
    #1
    1. Advertising

  2. Vesa Juvonen

    Brock Allen Guest

    The only thing I can think of off the top of my head is if the CSS is not
    marked as an embedded resource in your assembly. Use reflector and open your
    assembly and check the resources to see if it's even there, and then if it
    is to make sure the name you're using is correct.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > Hi,
    >
    > I'm developing a custom control using VS2005. The control has embedded
    > resources with it (js, images and css) and when control is rendered to
    > page, it uses the GetWebResourceUrl funtion to get correct address for
    > the resources (resources are streamed directly from assembly using
    > WebResource.axd).
    >
    > Everything works well with images and javascript files, but for some
    > reason the css files are not streamed correctly. Is this a
    > restrictions in the HttpHandler, or something else?
    >
    > In this case the web site level Themes or css files are not an option
    > (these are not suitable for reusable control development). Of course
    > the css attributes could be applied to each html element individually,
    > but this would cause repeating the style attributes for each element,
    > which would cause the page sizes to increase unnecessarely.
    >
    > Sample code to demostrate
    >
    > -----------------------------------------
    >
    > <Assembly: WebResource("foo.gif", "image/gif")> - As a assembly
    > attribute
    >
    > Me.Page.ClientScript.GetWebResourceUrl Me.GetType, "foo.gif") - for
    > img src
    >
    > Let's put the link address of image (from client side page) to browser
    > address box: We can see the image from the assembly.
    >
    > <Assembly: WebResource("foo.css", "text/css")>
    >
    > Me.Page.ClientScript.GetWebResourceUrl Me.GetType, "foo.css") - for
    > htmllink href property
    >
    > Let's put the link address of css file (from client side page) to
    > browser address box: We get empty html page... which was not
    > expected.We would like to have the css file as in the image case.
    >
    > --
    >
    > There's an excellent article concerning this functionality in te MSDN
    > including sample files:
    >
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs0
    > 5/html/webresource.asp
    >
    > However the samples provided in this article don't work with the
    > released version of VS2005 (built on earlier version), due minor
    > changes in class members. f.ex the LinkedStyleSheet is no more
    > accessable from the controls in the page, since the function has been
    > swithed to protected. Well. in sense ot current problem, this is not
    > the issues, since we can by pass this problem using Header.Controls
    > collection and HtmlLink class.
    >
    > --
    >
    > Thanks in Advance
    >
    > - Vsku
    >
     
    Brock Allen, Nov 11, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jaydev

    Webresource css file issue

    jaydev, Dec 1, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    348
    jaydev
    Dec 4, 2006
  2. Matthew  Brealey

    Accessing a WebResource from a .skin file

    Matthew Brealey, Feb 6, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    335
    Matthew Brealey
    Feb 6, 2007
  3. jaydev

    Webresource css file issue

    jaydev, Dec 1, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    99
    jaydev
    Dec 1, 2006
  4. jaydev

    Webresource css file issue

    jaydev, Dec 1, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    107
    jaydev
    Dec 1, 2006
  5. jaydev

    Webresource css file issue

    jaydev, Dec 1, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    99
    jaydev
    Dec 1, 2006
Loading...

Share This Page