using a control from within a control

S

shiretu

Hi,

In your target page (that containing the generated image) put a <img>
tag with the src pointed to a regular aspx page. The src url can
contain the parameters of your chart embeded in a get form. For
example:

<img src="chartgenerator.aspx?radius=5&slice1=20&slice2=45&slice3=35>

Now, in chartgenerator.aspx you can get the variables from the "GET"
request, interpret those variables and generate the image accordingly.
For this, you need a image library or you can build your own (don't
reinvent the whel, just search for such a library). After the image was
generated (now, it is contained in a byte array), set the mime type to
the type of the image and Response.WriteBinary(...) the content of the
image.

One more thing....
The <img....> tag can be a Image web control and you can dinamically
build the src in your code associated with the target page (the page
showing the chart)


Hope it helps....
 
J

Jon Paal

thanks for helping, I need a little more assistance.

it appears the example code, from the link, is returning another control to the web form, as opposed to adding an image, using the
code:

"me.controls.add(chart)"

where "chart" is the control that actually produces the final image.

When I try to put "me.controls.add(chart)" into my custom control, it does not pass through to the web form.

How might I add the "chart" control to the output stream of my htmltextwriter ?
 
S

shiretu

Hi,

It does not matter if the <img......> tag is manually coded into the
HTML part of the page or if it is a control that finally outputs the
tag. All you have to do is to set the src to the page(NOT CONTROL!!!)
that will generate the image. It must be a page,not a control, because
the page is used in the src part of the img tag. Besides, you may want
to set the mime type of the response generated by the page. A control
can't do that because it must be a part of a page (text/html).

So you have to follow 2 steps:

1. Build a page that renders the image. I will call this page
chartgenerator.aspx. This page can take some parameters in a "GET"
request, parameters used to get the chart data. Now, if you access
http://localhost/myapp/chartgenerator.aspx?param1=val1&param2=val2 the
output should be a image (JPG,GIF,etc). NO HTML. Just the image. This
is possible if you set the mimetype of the page properly and
Response.WriteBinary(...) the byte array of the image (see prev.
post). I really don't remember now the name of the property for the
mimetype thing. I only know that it is a property of the
System.Web.UI.Page (the base class of your chartgenerator.aspx)

2 a. Add a <img src="chartgenerator.aspx?param1=val1&param2=val2" ....>
to your page containing the chart
OR
2.b Build a control that can generate the tag described at 2.a. With
this method, you can generate the "?param1=val1&param2&val2" of the
link from the control's custom properties. It will be than available at
design time too :D

Bottom line...
1. You need a page able to generate an image from the parameters
received in a GET request
2. Any dinamically or hardcoded way of building the src attribute of
the img tag
3. Any dinamically or hardcoded way of printing the img tag itself
(along with the generated src) in the final HTML response

Hope it helps...
 
S

shiretu

Oooooops.... I don't know what is the matter with me... I didn't read
your first message verry well (even if it is a short one :p ). Sorry, I
was missleading you. You can use my method but it is a little more
difficult. Sorry but I really don't know that control at all and I
don't have the time necesarry to play with it :((

Sorry again...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top