473,683 Members | 3,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I make, store in memory and return spacer image in C#2.0/aspx?

Hello,

On a high volume page we have the following javascript:
img = new Image()
img.src = 'http://myserver.com/count.aspx?x=1' ;

and it works fine, but now we've added:
img.onload = myImgLoaded

and it fails on IE and FF. The reason being it's not returning a proper
image, simply text. When a gif/jpg is returned it fires the onload event
every time.

Below I've sketched out how I might get the aspx page to return as an image,
but I would greatly appreciate help flushing it out.

void Application_Sta rt(object sender, EventArgs e)
{
// i think i have to start with a bmp, not sure how to get it to gif or jpg
Bitmap bitmapSpacer = new Bitmap(1, 1);
}

private void Page_Load(objec t sender, System.EventArg s e)
{
// set the header
Response.Conten tType = "image/gif";

// misc biz logic here

// return the image
// keep in mind I don't want to create this image each page loads nor load
it from the hard drive nor create a img tag
Response.Write( bitmapSpacer); // Can it can be returned this way?
}

Thank you.
Oct 14 '06 #1
4 1805
Assign onload event before you assign src.

var img = new Image();
img.onload = myImageLoad;
img.src = 'http://myserver.com/count.aspx?x=1' ;

It always happens when image is cached on the client machine and because of
this it's loaded before event handler is known.

Hope this helps
--
Milosz Skalecki
MCP, MCAD
"Mark S." wrote:
Hello,

On a high volume page we have the following javascript:
img = new Image()
img.src = 'http://myserver.com/count.aspx?x=1' ;

and it works fine, but now we've added:
img.onload = myImgLoaded

and it fails on IE and FF. The reason being it's not returning a proper
image, simply text. When a gif/jpg is returned it fires the onload event
every time.

Below I've sketched out how I might get the aspx page to return as an image,
but I would greatly appreciate help flushing it out.

void Application_Sta rt(object sender, EventArgs e)
{
// i think i have to start with a bmp, not sure how to get it to gif or jpg
Bitmap bitmapSpacer = new Bitmap(1, 1);
}

private void Page_Load(objec t sender, System.EventArg s e)
{
// set the header
Response.Conten tType = "image/gif";

// misc biz logic here

// return the image
// keep in mind I don't want to create this image each page loads nor load
it from the hard drive nor create a img tag
Response.Write( bitmapSpacer); // Can it can be returned this way?
}

Thank you.
Oct 14 '06 #2
Milosz;

Thank you, but I wasn't looking for feedback on the Javascript. For the
record, the code doesn't have to live in an onload, to avoid caching we use
img.src = 'http://myserver.com/count.aspx?x=1& cacheBuseter='+ Math.random();

The Javascript works just fine, there's no problem firing the img onload
event IF an image is returned.

Thanks anyways, and to the rest of the group, please consider this question
still open for feedback.


"Milosz Skalecki" <mi*****@REMOVE ITwp.plwrote in message
news:05******** *************** ***********@mic rosoft.com...
Assign onload event before you assign src.

var img = new Image();
img.onload = myImageLoad;
img.src = 'http://myserver.com/count.aspx?x=1' ;

It always happens when image is cached on the client machine and because
of
this it's loaded before event handler is known.

Hope this helps
--
Milosz Skalecki
MCP, MCAD
"Mark S." wrote:
>Hello,

On a high volume page we have the following javascript:
img = new Image()
img.src = 'http://myserver.com/count.aspx?x=1' ;

and it works fine, but now we've added:
img.onload = myImgLoaded

and it fails on IE and FF. The reason being it's not returning a proper
image, simply text. When a gif/jpg is returned it fires the onload event
every time.

Below I've sketched out how I might get the aspx page to return as an
image,
but I would greatly appreciate help flushing it out.

void Application_Sta rt(object sender, EventArgs e)
{
// i think i have to start with a bmp, not sure how to get it to gif or
jpg
Bitmap bitmapSpacer = new Bitmap(1, 1);
}

private void Page_Load(objec t sender, System.EventArg s e)
{
// set the header
Response.Conte ntType = "image/gif";

// misc biz logic here

// return the image
// keep in mind I don't want to create this image each page loads nor
load
it from the hard drive nor create a img tag
Response.Write (bitmapSpacer); // Can it can be returned this way?
}

Thank you.

Oct 14 '06 #3
Sorry, i was misled by 'we added onload and it stoped working'. I created an
example that should fixed the problem.

1. page generating the counter gif:

using System;
using System.Web;
using System.Drawing;

public partial class Counter : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
const int DefaultCounterV alue = 0;
int counter;

if (!int.TryParse( Request.QuerySt ring["x"], out counter))
counter = DefaultCounterV alue;
System.Drawing. Image image = GenerateCounter Image(counter);
image.Save(Resp onse.OutputStre am, System.Drawing. Imaging.ImageFo rmat.Gif);

Response.Conten tType = "image/gif";
Response.End();

}

private System.Drawing. Image GenerateCounter Image(int counter)
{
const int Width = 100;
const int Height = 30;

Bitmap image = new Bitmap(Width, Height);
Graphics graphics = Graphics.FromIm age(image);
Font font = new Font("Arial", 10.0f);

graphics.FillRe ctangle(Brushes .Yellow, 0, 0, Width, Height);
graphics.DrawSt ring(counter.To String(), font, Brushes.Red, new PointF(1,
1));
graphics.Dispos e();
font.Dispose();

return image;
}
}
and test html on another page:

<script language="javas cript">
var g_img = new Image();
g_img.onload = myImageLoad;
g_img.src = 'counter.aspx?x =1';

function myImageLoad()
{
var counterImage = document.getEle mentById('<%=co unterImage.Clie ntID %>');
counterImage.sr c = g_img.src;
}
</script>

<img runat="server" id="counterImag e" alt="loading... "/>
hope this helps
--
Milosz Skalecki
MCP, MCAD
"Mark S." wrote:
Milosz;

Thank you, but I wasn't looking for feedback on the Javascript. For the
record, the code doesn't have to live in an onload, to avoid caching we use
img.src = 'http://myserver.com/count.aspx?x=1& cacheBuseter='+ Math.random();

The Javascript works just fine, there's no problem firing the img onload
event IF an image is returned.

Thanks anyways, and to the rest of the group, please consider this question
still open for feedback.


"Milosz Skalecki" <mi*****@REMOVE ITwp.plwrote in message
news:05******** *************** ***********@mic rosoft.com...
Assign onload event before you assign src.

var img = new Image();
img.onload = myImageLoad;
img.src = 'http://myserver.com/count.aspx?x=1' ;

It always happens when image is cached on the client machine and because
of
this it's loaded before event handler is known.

Hope this helps
--
Milosz Skalecki
MCP, MCAD
"Mark S." wrote:
Hello,

On a high volume page we have the following javascript:
img = new Image()
img.src = 'http://myserver.com/count.aspx?x=1' ;

and it works fine, but now we've added:
img.onload = myImgLoaded

and it fails on IE and FF. The reason being it's not returning a proper
image, simply text. When a gif/jpg is returned it fires the onload event
every time.

Below I've sketched out how I might get the aspx page to return as an
image,
but I would greatly appreciate help flushing it out.

void Application_Sta rt(object sender, EventArgs e)
{
// i think i have to start with a bmp, not sure how to get it to gif or
jpg
Bitmap bitmapSpacer = new Bitmap(1, 1);
}

private void Page_Load(objec t sender, System.EventArg s e)
{
// set the header
Response.Conten tType = "image/gif";

// misc biz logic here

// return the image
// keep in mind I don't want to create this image each page loads nor
load
it from the hard drive nor create a img tag
Response.Write( bitmapSpacer); // Can it can be returned this way?
}

Thank you.


Oct 15 '06 #4
Thank you, your code showed me the way to succesfully returning the gif.

"Milosz Skalecki" <mi*****@REMOVE ITwp.plwrote in message
news:78******** *************** ***********@mic rosoft.com...
Sorry, i was misled by 'we added onload and it stoped working'. I created
an
example that should fixed the problem.

1. page generating the counter gif:

using System;
using System.Web;
using System.Drawing;

public partial class Counter : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
const int DefaultCounterV alue = 0;
int counter;

if (!int.TryParse( Request.QuerySt ring["x"], out counter))
counter = DefaultCounterV alue;
System.Drawing. Image image = GenerateCounter Image(counter);
image.Save(Resp onse.OutputStre am, System.Drawing. Imaging.ImageFo rmat.Gif);

Response.Conten tType = "image/gif";
Response.End();

}

private System.Drawing. Image GenerateCounter Image(int counter)
{
const int Width = 100;
const int Height = 30;

Bitmap image = new Bitmap(Width, Height);
Graphics graphics = Graphics.FromIm age(image);
Font font = new Font("Arial", 10.0f);

graphics.FillRe ctangle(Brushes .Yellow, 0, 0, Width, Height);
graphics.DrawSt ring(counter.To String(), font, Brushes.Red, new PointF(1,
1));
graphics.Dispos e();
font.Dispose();

return image;
}
}
and test html on another page:

<script language="javas cript">
var g_img = new Image();
g_img.onload = myImageLoad;
g_img.src = 'counter.aspx?x =1';

function myImageLoad()
{
var counterImage = document.getEle mentById('<%=co unterImage.Clie ntID %>');
counterImage.sr c = g_img.src;
}
</script>

<img runat="server" id="counterImag e" alt="loading... "/>
hope this helps
--
Milosz Skalecki
MCP, MCAD
"Mark S." wrote:
>Milosz;

Thank you, but I wasn't looking for feedback on the Javascript. For the
record, the code doesn't have to live in an onload, to avoid caching we
use
img.src =
'http://myserver.com/count.aspx?x=1& cacheBuseter='+ Math.random();

The Javascript works just fine, there's no problem firing the img onload
event IF an image is returned.

Thanks anyways, and to the rest of the group, please consider this
question
still open for feedback.


"Milosz Skalecki" <mi*****@REMOVE ITwp.plwrote in message
news:05******* *************** ************@mi crosoft.com...
Assign onload event before you assign src.

var img = new Image();
img.onload = myImageLoad;
img.src = 'http://myserver.com/count.aspx?x=1' ;

It always happens when image is cached on the client machine and
because
of
this it's loaded before event handler is known.

Hope this helps
--
Milosz Skalecki
MCP, MCAD
"Mark S." wrote:

Hello,

On a high volume page we have the following javascript:
img = new Image()
img.src = 'http://myserver.com/count.aspx?x=1' ;

and it works fine, but now we've added:
img.onload = myImgLoaded

and it fails on IE and FF. The reason being it's not returning a
proper
image, simply text. When a gif/jpg is returned it fires the onload
event
every time.

Below I've sketched out how I might get the aspx page to return as an
image,
but I would greatly appreciate help flushing it out.

void Application_Sta rt(object sender, EventArgs e)
{
// i think i have to start with a bmp, not sure how to get it to gif
or
jpg
Bitmap bitmapSpacer = new Bitmap(1, 1);
}

private void Page_Load(objec t sender, System.EventArg s e)
{
// set the header
Response.Conte ntType = "image/gif";

// misc biz logic here

// return the image
// keep in mind I don't want to create this image each page loads nor
load
it from the hard drive nor create a img tag
Response.Write (bitmapSpacer); // Can it can be returned this way?
}

Thank you.



Oct 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
11999
by: Versteijn | last post by:
Hello all I have a ASPX file called scaleimage.aspx that scales my images down to a given width. This page is used very much in web project I am working on. But due to the large size of the images I randomly get images (error) in Internet Explorer. When I open one individual image at that point I read this exception:
6
14692
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm using the Imagebutton.Attributes.Add("onMouseOver","this.src = 'somepicture.jpg') and that works fine. I've tried some java script to change the other control's visible property by changing is className, but that doesn't seem to work
5
3160
by: drdave | last post by:
Hi, I have 6 forms being generated using coldFusion, they are named special1, special2 special3 and so on.. in these forms I have a link to open a new window. I am trying to pickup the formname passed along to the new window.. the window opener function is: <SCRIPT LANGUAGE = "JavaScript">
6
4875
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
0
1175
by: Samy | last post by:
Hi There, I am trying to display images in a gridview and display only valid images from the html in the database (and not display spacers, 1x1 pixel images etc). For this, I have a gridview with an asp:Image control in one of its template. I populate the image by setting the imageurl (remote url) of the image in the rowdatabound event of the gridview. I have an aspx page called draw.aspx and i do it this way.. imageurl =...
0
994
by: Roland Schwarz | last post by:
Most probably what I am asking for already has been answered somewhere, still I was not able to find:-( I want to encapsulate a class ( a primitive type for the beginning ) to behave like a lvalue, but instead of living in process memory being forwarded to some remote store. I believe an lvalue needs to be able to be convertible to its wrapped type on reading, and providing an
2
2695
by: Jay | last post by:
I have a web app running on the windows CE device. In one of the asp.net pages - it has javascript code. That seems to have a memory leak. When I run the web app - in about one hour, the app hangs. I looked at the memory and it seems to be full. I removed all the javascript code - and the app seems to be have no leaks. As soon as I include my javascript code - the memory consumption gradually increases. Whether I actually invoke the...
3
2836
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the solution done already. I have built an ASP.NET that queries an Index Server and returns a...
1
47456
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8771
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5789
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4519
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2934
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2195
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.