Last post Apr 27, 2010 10:30 PM by hans_v
Apr 23, 2010 12:24 PM|djpark|LINK
I have a simple HttpHandler that generates a dynamic image based on query string parameters and a custom web control that renders an image tag pointing to the handler as its 'src' attribute. All works fine when run in the web server, but at design time
the control displays as the "missing image" icon (red x in a box).
The handler is registered in the web.config with a ".ashx" extension.
The RenderContents method in the control looks like this:
<span id="ProgressMeter2"><img src="~/Sparklines.SparkHandler.ashx?stype=pm&w=100&h=15&sv=0&ev=100&cv=0&sc=Green&ec=Green&mc=White&gs=None" /></span>
Can anyone explain how I can get the image to show in the designer?
Apr 27, 2010 10:23 PM|rstrahl|LINK
I don't think this is going to work. The problem is that that the designer doesn't actually 'run' virtual path links (~) but resolves them through the virtual path provider and based on that figures out what to display. IOW, there's no HTTP request sent
out to the "http://localhost/YourApp/YourHandler.ashx" to serve the image url.
What you can do in your control do the translation of the URL yourself using ResolveUrl and assign that url to the image instead of the virtual path in conditional code that runs when the designer is active (or in a dedicated ControlDesigner class).
+++ Rick ---
Apr 27, 2010 10:30 PM|hans_v|LINK
The tilde (~) is processed by ASP.NET. However, you're using it in a normal HTML tag, which isn't processed by ASP.NET. Either use a ASP.NET Image control, or add the runat="server" attribute to the image tag:
<img runat="server" src="~/Sparklines.SparkHandler.ashx? stype=pm&w=100&h=15&sv=0&ev=100&cv=0&sc=Green&ec=Green&mc=White&gs=None" />