embedding image in page

M

Marc Pelletier

Hello,

I have a class (TideClass) which creates a bitmap image as one of its
functions. I want to create a page which has this image embedded amongst
some text. I know that I have to stream the image back from a separate
aspx page.

I have therefore created a page Day1.aspx which gets the instance of tide
from the context handler, calls the DrawChart function and streams it
back.

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
DataForm1 Page1 = (DataForm1)Context.Handler;
tide = Page1.tide;
}

Bitmap b = new Bitmap( 500, 350 );
b = tide.DrawChart1( 500, 350 );
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();
b.Dispose();
}

The calling page (TideForm.aspx) instantiates the tide object and fills
some labels with properties of the tide object, then calls Day1.aspx to
draw the chart. It also references the original page to get the user
selection:
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
DataForm1 Page1 = (DataForm1) Context.Handler;
Label1.Text = String.Format( "Station ID: {0}", Page1.Station_ID );
Label3.Text = String.Format( "{0:MMM dd, yyyy}", Page1.StartDate );
tide = new TideClass( Page1.Station_ID );
Page1.tide = tide;
tide.CalcDays( sdate, Page1.NumDays );

Label2.Text = tide.StationName;

Server.Transfer("OneDay.aspx");
}

However the resulting page contains ONLY the chart and not the labels
which I would have thought were streamed first. This confirms that my
code on Day1.aspx is correct, at least.

My next effort was to include an image on TideForm. I dropped a
WebControl.Image on there and set the imageurl to Day1.aspx. I've tried
setting the imageurl property dynamically after I know the tide object
has been created, and I've set the url statically, but a breakpoint in
the Day1.Page_load method never gets triggered and the image is displayed
empty.

I'm stumped. None of the examples I've found places an image on a page
with other elements.

I guess my question is how do I display dynamic data in a Webcontrol
Image component? Alternatively, how do I embed an image within other
content?

thanks

Marc Pelletier
 
T

Tonix

Hi,

Placing an Image control and seting its ImageUrl to another ASPX page which
provides image binary stream, the approach should work. My suggestion is to
check the rendered img src in the html source to see if it's correctly
directed to your desired server page. And you may also open the img src as
url in your web browser to see the error message if any.

In your codes of TideForm.aspx, the call "Server.Transfer" will bypass
rendering the page itself. Therefore, you will only see the image, without
any contents you desire from TideForm.aspx.

For calling Day1.aspx by setting ImageUrl or src, I doubt whether you are
able to get the "Context.Handler" or not. I am not sure.

Hope it helps.

Regards,
Tonix
 
M

Marc Pelletier

For calling Day1.aspx by setting ImageUrl or src, I doubt whether you are
able to get the "Context.Handler" or not. I am not sure.

This appears to be the problem. If i use server.transfer to get to that
page the context is good, but using a url on an image component its not. It
fails without an error message, which is what tricked me.

So now the question is, how do I reference my object from the embedded
page, if I can't use a context handler? Or how do I embed an image without
using an image component?

thanks

Marc Pelletier
 
T

Tonix

1. You dont have to use Server.Transfer and Context.Handler to pass
data. You may consider using Session states or QueryString more
simple.

2. You may write HTML tag "img" and bind the "src" attribute, instead
of using web control. But i think it doesnt make difference for your
problem.

Regards,
Tonix
 
M

Marc Pelletier

(e-mail address removed) (Tonix) wrote in @posting.google.com:
1. You dont have to use Server.Transfer and Context.Handler to pass
data. You may consider using Session states or QueryString more
simple.

Sorry for the late reply, I've been out. Yes this is what I've done. I had
some really wrong ideas about sessions, that have been improved!

Thanks

Marc Pelletier
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top