Have you got mixed up and tried to subclass a user control rather than a web control.
Are you in fact after this:
public class ImageGenerator : System.Web.UI.WebControls.
Hi!
I have to generate a bitmap at runtime and display it on my web page, so I decided to create a custom Web User Control. It's code is in code section.
The problem is, I can't specify control's dimensions on aspx page. When I put the control on a page and run it, I can see the upper-left part of the generated bitmap, but the rest is hidden by the boundries of the control. I can't see "style", "height", "width" or any similar property on my control.
As you can see, I made some attempts to add those properties, but it's not working because System.Web.UI.UserControl doesn't have those or any similar propeties to which I could map my properties.
What should I do to add those properties to my control?
Also, if my generated bitmap is larger than the size of the control, then it should have scrollbars.
Since these are 2 questions in 1, I'll award 250 points for size solution and 250 to scrollbars solution.
P.S. If you were wondering why I'm doing this, I'm creating my own custom chart diagram which can greatly vary in dimensions, so having control over it's dimensions or having ability to scroll it, is important.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks for response.
I'm creating custom control by right clicking on my project name and selecting add new web user control.
When I do that, it automaticaly inherits System.Web.UI.UserControl.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ImageGenerator.a
When I manualy change it to inherit System.Web.UI.WebControls.
Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)
I tried googling about it and found that I should change 'CodeFile' attribute to 'CodeBehind', but then I get this error:
Could not load type 'ImageGenerator'.
I found sever articles saying this error happens when sollutions is not compiled, but I can't compile it becouse this error arrises when I try to build the sollution.
I want to be able to create a control which already has all common properties and functionality like all other asp controls. (Width, height, style, tag, CssClass, Visible, Enabled, etc.)
Just like user control in desktop application. You get empty background with everything you need to put it on the form. Then just extend it with functionality you need.
Yep there is a big difference.
Read something like this if you have time.
http://support.micros
A quick heads up though is that a user control works just like a page but it is just a small part of a page - eg a header, footer, menu. It has an ascx extension rather than aspx and it has code behind just like a page.
Custom controls are pure code and work more like the built in controls - eg Textbox, DropDownList etc.
I suspect it is a custom control that you need but do a little reading first if you have time.
I think I understand the difference.
I'd like to do it with user control, as it seems simpler. So this means I have to create a <div> element or something similar inside the control, and specify width and height of the div.
Example in the code section does all that, plus it has scroll bars when picturebox is larger that div.
But when I try to generate the image using code from my first post (in page_load event), it overwrites the entire contents of the web page. I can see only generated image.
This makes sense, because I'm writing directly to Response object.
I know this is not the main question of this post, but maybe you know the solution. (You'll get the points regardless if you answer this or not)
Is there a way to specify exactly where Response output will go (for example inside <div>) or is there another way to put System.Drawing.Bitmap on a web page without saving it on the file system first?
Ok thought it would be something like that.
I have done this kind of thing before and I think what you need to do is create a page whose sole job is the creation of images (Call it ImageFactory.aspx or somethign like that). Parameters for which image to be created can be passed in as querystring parameters.
Then in your other page/control you place an image server control or even just a plain old html image tag but you set the src of the image to the url of the page(with querystring parameters if required).
Hope that make sense?
Yep.
It makes sense. In fact I was just reading an article I found which explains how something like this works.
Here's the link for future reference:
http://www.developerfusion
Thanks again for your help.
To conclude this thread, I'm posting the example here. Maybe it will help someone else.
It generates an image with circles. Number of circles, back color and fore color can be controled from the page where control is hosted.
Solution consists of 3 parts:
- ImageGenerator.aspx
- ImageGenerator.ascx
- Default.aspx
When button on the main page is pressed, properties of ImageGenerator1 are set and and its GenerateImage() method is called.
GenerateImage method creates an url with parameters and sets Image1 control to point to this url.
When ImageGenerator.aspx is loaded it reads the request parameters, generates the image and writes it to Response.OutputStream
Business Accounts
Answer for Membership
by: dbrckoviPosted on 2009-06-17 at 10:19:09ID: 24650458
I forgot to mention, I can't use picturebox or other similar control because they use ImageUrl property to display the image.In this case I would first have to save generated image to server's file system and then link it to picturebox, but I don't want to save anything to disk.