[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Adding a click event to an image generated from a byte array in ASP.NET

Kevin B Ebert

1/21/2003 10:10:00 PM

I have created a webservice that return a byte array that represents
an image I wan to display on an ASP.NET page. In addition to
displaying the image on the page, I want to add a click event to the
image that will grab the x, y coordinates of the click. The
ImageButton control appears to only allow me to point to an image
located on the server, but not anything else, i.e., my byte array.

I've included my code below if anyone want to try and make sense of
it:

Event Class: This is the class I created to define my event.
public class OnClickEventArgs : System.EventArgs
{
private int m_X;
private int m_Y;

public OnClickEventArgs(int x, int y)
{
m_X = x;
m_Y = y;
}

public int X
{
get { return m_X; }
}
public int Y
{
get { return m_Y; }
}
}

My Image Control Class: This is the class I created to act as my
control for loading the image.
public abstract class ImageControl : System.Web.UI.UserControl,
IPostBackEventHandler
{
private byte[] aImage;

private void Page_Load(object sender, System.EventArgs e)
{
Response.BinaryWrite(aImage);
}
public delegate void OnClickEventHandler(object sender,
OnClickEventArgs e);
public event OnClickEventHandler OnClick;

public byte[] Image
{
get { return aImage; }
set { aImage = value; }
}


public void RaisePostBackEvent(string eventArgument)
{
OnClick(this, new OnClickEventArgs(0,0));
}

}


My Web Page: This is a code snippet from my webpage where I load the
control and try using it to display the image and raise the event.
I'm able to display the image no problem. I just can't get the
OnClick event to work for it:

private void Page_Load(object sender, System.EventArgs e)
{
ImageControl mapImage = Page.FindControl("mapImageControl") as
ImageControl;
mzhang2000.MapWebService mapService = new mzhang2000.MapWebService();
byte[] aByteArray = new byte[1];
string serverMessage = "";

mapService.GetSimpleMap("HelloWorld", 50.0, -95.3, 29.7, 500, 400,
ref aByteArray, ref serverMessage);
mapImage.Image = aByteArray;

mapImage.OnClick += new
ImageControl.OnClickEventHandler(this.mapImageControl_OnClick);
}

private void mapImageControl_OnClick(object sender, OnClickEventArgs
e)
{
}

Please respond to this thread, I do not check my hotmail email
account.