Last post May 15, 2008 12:36 PM by jkirkerx
May 07, 2008 09:20 PM|Gahawn|LINK
I'm writing my own version of the ImageButton control with extra bells & whistles. I need special rendering to do this. I have it working great at runtime. I can pass the relative URL of an image (such as "~/images/_default.png") and it draws perfectly at
runtime. At design time I can't for the life of me load the Bitmap because I can't resolve the relative URL into a physical path that the designer can use. Can anyone help me with this issue?
May 08, 2008 12:33 AM|albertpascual|LINK
You can steam the bitmap to the browser by setting the header and Response.Write. Is that what you asking?
May 08, 2008 02:19 PM|Gahawn|LINK
No, that's not quite what I need. I need to be able to figure out the physical path of the file so the Bitmap.LoadFile() function knows how to find it.
May 09, 2008 07:49 PM|jkirkerx|LINK
.png files don't show in the render view mode for some reason. It's a Visual Studio issue.
May 10, 2008 08:56 AM|Ddutch|LINK
I am doing something like you: developing an ImageButton derived control that will create a button on the fly if it does not exists already, otherwise it should just make the reference to the existing image. I have also a problem with rendering at design
time (At runtime it works without a hitch). I get the error Object reference not set to an instance of an object, which is too vague to get a hint to where to seek for the error. (This also happens when the image exists).
For finding the physical path, you can use:
that will return the physical path.
I am trying to find out how to monitor/debug the designtime code to find the error, but have not found a way yet. (using VS2008 standard). Anybody has an idea how to debug the design time code?
Hendrik M.J. Arnoldus
web custom control
visual studio 2008
May 11, 2008 03:03 PM|jkirkerx|LINK
Debugging the design view code is tricky.
We detect the design view mode, and run time mode, and have 2 different programs that we run for each scenario.
Private Sub RenderDesignView(ByVal writer As HtmlTextWriter)
In design view mode, we just write enough code to display the control on the screen, so the user can change the properties, and see the results. They can model and design the control to their liking.
In run time mode, our code picks up all the property values to render the looks of the control like the design view, but also processess data such as load and so forth.
We make it a practice to model our designs in RenderDesignView until we get the look and feel that we want, and copy the code to CreateChildControls and add our data logic to it.
Objects not set to an instance of an object means that you made a call to a control or object that does not exist at the time of run. You can look at the error output, and it will tell you what page and module or function it came from.
In design mode with the bold red letters, it's usually trying to load data into a control, or call clientscript or something.
Remember, you can't run code in Design View. That's why it's called design view!. You just design and view.
May 14, 2008 08:29 AM|Ddutch|LINK
Ok, that was a usefull suggestion, as it allowed to start with very simple code, and extending that bit by bit. Thus I discovered that it was properly the line of code that I suggested to Gahan:
string path = HttpContext.Current.Server.MapPath ("~/Images/_default.png");
that is not executed at design time and causes the "reference not set to instance" error message.
May 14, 2008 03:15 PM|jkirkerx|LINK
Server controls seem to be a different beast. You have to be so careful when you construct them. Debugging them is hard to do, and takes months of practice.
Good Call on the error, Server Map Path does not work in design mode. I've never been able to get a png to display in design mode.
May 15, 2008 08:57 AM|Ddutch|LINK
That is strange, I do not have this problem (using VS2008 standard). a png with a src="some relative path" (set by using the imageurl property at designtime) shows without problems.
May 15, 2008 12:36 PM|jkirkerx|LINK
That is weird. Maybe my fireworks is too old or something.