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?
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.
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).
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
ControlDesigner"design-time"server controlImageUrl"custom control"runtimeweb custom controlvisual studio 2008Design Time
We detect the design view mode, and run time mode, and have 2 different programs that we run for each scenario.
Example:
Private Sub RenderDesignView(ByVal writer As HtmlTextWriter)
End Sub
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.
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.
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.
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.
Gahawn
0 Points
8 Posts
Render Bitmap at design time
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?
Thanks much.
albertpascua...
All-Star
17520 Points
3475 Posts
MVP
Re: Render Bitmap at design time
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?
Al
My Blog
Gahawn
0 Points
8 Posts
Re: Render Bitmap at design time
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.
jkirkerx
Contributor
3750 Points
873 Posts
Re: Render Bitmap at design time
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.
Ddutch
Member
45 Points
19 Posts
Re: Render Bitmap at design time
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:
string path = HttpContext.Current.Server.MapPath ("~/Images/_default.png");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
ControlDesigner "design-time" server control ImageUrl "custom control" runtime web custom control visual studio 2008 Design Time
The Multi-Language Personal WebSite.
jkirkerx
Contributor
3750 Points
873 Posts
Re: Render Bitmap at design time
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.
Example:
End SubIn 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.
Ddutch
Member
45 Points
19 Posts
Re: Render Bitmap at design time
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.
Thanks,
Hendrik M.J. Arnoldus
The Multi-Language Personal WebSite.
jkirkerx
Contributor
3750 Points
873 Posts
Re: Render Bitmap at design time
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.
Ddutch
Member
45 Points
19 Posts
Re: Render Bitmap at design time
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.
Hendrik M.J. Arnoldus
The Multi-Language Personal WebSite.
jkirkerx
Contributor
3750 Points
873 Posts
Re: Render Bitmap at design time
May 15, 2008 04:36 PM|LINK
That is weird. Maybe my fireworks is too old or something.