using a control from within a control

Discussion in 'ASP .Net Building Controls' started by Jon Paal, Mar 3, 2006.

  1. Jon   Paal

    Jon Paal Guest

    I am developing a server control which will output some html and would like to have it also to return a bar chart image generated
    from this control:

    http://www.codeproject.com/aspnet/webchart.asp

    how can I call the bar chart control and have it return an image with my html ?
    Jon Paal, Mar 3, 2006
    #1
    1. Advertising

  2. Jon   Paal

    shiretu Guest

    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....
    shiretu, Mar 3, 2006
    #2
    1. Advertising

  3. Jon   Paal

    Jon Paal Guest

    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 ?




    "shiretu" <> wrote in message news:...
    > 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....
    >
    Jon Paal, Mar 3, 2006
    #3
  4. Jon   Paal

    shiretu Guest

    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...
    shiretu, Mar 4, 2006
    #4
  5. Jon   Paal

    shiretu Guest

    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...
    shiretu, Mar 4, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KatB
    Replies:
    0
    Views:
    444
  2. mark4asp
    Replies:
    2
    Views:
    2,214
    Harry Haller
    Nov 7, 2006
  3. Elmo Watson
    Replies:
    1
    Views:
    599
    Eliyahu Goldin
    May 8, 2007
  4. RichB
    Replies:
    3
    Views:
    282
    oogity
    Sep 22, 2008
  5. Abe
    Replies:
    2
    Views:
    167
Loading...

Share This Page