Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 15, 2008 04:36 PM by jkirkerx
May 08, 2008 01:20 AM|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 04:33 AM|LINK
You can steam the bitmap to the browser by setting the header and Response.Write. Is that what you asking?
May 08, 2008 06:19 PM|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 11:49 PM|LINK
.png files don't show in the render view mode for some reason. It's a Visual Studio issue.
May 10, 2008 12:56 PM|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 07:03 PM|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 12:29 PM|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 07:15 PM|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 12:57 PM|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 04:36 PM|LINK
That is weird. Maybe my fireworks is too old or something.