Last post Dec 10, 2007 03:14 PM by cool2000
Sep 15, 2007 09:35 AM|cool2000|LINK
I have a .aspx file that draws a single-pixel width (vertical) gradient called DrawGradient.aspx. I know this code works because when I say:
<img src="GDIs/DrawGradient.aspx?startColor=0000ff&endColor=aaaaff&height=50" />
<asp:Image runat="server" ImageUrl="GDIs/DrawGradient.aspx?startColor=0000ff&endColor=aaaaff&height=50" />
The image does show up on the page as expected.
Now I have the following markup on a page:
... Content here ...
AND the CSS file (DivBoxes.css)
background: url('GDIs/DrawGradient.aspx?startColor=0000ff&endColor=aaaaff&height=50') top left repeat-x;
I did reference the CSS file from/in the page that contains the div: <link rel="stylesheet" src="DivBoxes.css" />
I've tried many things like starting the url string with / or even ~/, or even putting the .aspx file in the same folder as the CSS file (which makes me not have to specify a folder for the DrawGradient.aspx file). What is it about the url string I have
here that CSS doesn't like? The .aspx?, the ?, the = sign, the &?
In general, though, how do we set the background image of a div if we want that background image to be created on the fly with GDI+?
CSS GDI GDI+ background image div rounded corners gradient LinearGradientBrush
Sep 15, 2007 01:36 PM|neutrino|LINK
I think they way you reference a CSS file is not
<link rel="stylesheet" src="DivBoxes.css" />
<link href="DivBoxes.css" rel="stylesheet" type="text/css" />
and this should be within the head element of the page.
This might be your problem.
Sep 15, 2007 04:38 PM|cool2000|LINK
You're right about the href instead of the src. I still have the problem, though. Yes, I do have the link tag in the page's head tag. ALL my CSS declarations work except the background: url('...aspx?..=..&..=...') declaration. It just doesn't draw/render
I found out by discovery, though, that setting the background works in the code file of the page in Page_Load:
protected void Page_Load(object s, EventArgs e)
string d_url = "GDIs/DrawGradient.aspx?startColor=ffcccc&endColor=ffffff&height=50";
GradientBox.Style.Add("background","url('" + d_url + "') top left repeat-x");
But it's so cumbersome to do it this way! Would this be the only way?
Sep 15, 2007 04:39 PM|cool2000|LINK
By the way, I redeclared the div:
<div id="GradientBox" class="GradientBox" runat="server"> so I can access it in the C# code.
I also change the id declaration in the CSS file to a class declaration so that I can still use the CSS file to declare other attributes.
Sep 28, 2007 04:03 AM|Menno van den Heuvel|LINK
I've been doing something quite similar to what you appear to be up to, and haven't had a single problem linking asp.net generated images. I know some older browsers take issue with single quotes around url's, but my guess would still be a problem in your
url, even though it seems you've all but ruled that out. Anyway, this is what works just fine for me:
background: url('http://localhost/GoCss/images_cvo.ashx?image=gologo&vestiging=690') top left repeat-x;
Maybe you could try linking your full url in your css?
Dec 10, 2007 03:14 PM|cool2000|LINK
Thank you for your response. I see that you put the full absolute URL including the http://. I think originally, CSS's url() function expects a string that starts with http://. I didn't have that to begin with. I assumed that ASP.net would automatically
inject the http:// when I give it the relative path to the aspx file.