|
Rank: Newbie Groups: Member
Joined: 6/30/2007 Posts: 3
|
I'm stuck!
If I have a callback panel and a imagebutton on it, how do I get the e.x and e.y from System.Web.UI.ImageClickEventArgs?
Regards Stefan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi Stefan, There seems to be no easy way to get e.x and e.y when you use image button with a callback. Ideally the CallbackPanel supposes to take care of it but obviously it did not. We will look into it and see if we can fix that. In the mean time, you can use the following workaround: 1. Instead of puting an image button in the form, you would put a regular HTML <img> element in the form; 2. Attach an onclick javascript event hanlder to the image button, it will be something like this:
Code: HTML/ASPX
<img src="something.gif" onclick="image_click(event)" />
The handler would then look like this:
Code: JavaScript
function image_click(e)
{
if (!e)
e = window.event;
//Get the x, y value
var x, y;
if (e.offsetX) //For IE
{
x = e.offsetX;
y = e.offsetY;
}
else //For FireFox
{
x = e.pageX - document.getElementById("divImage").offsetLeft;
y = e.pageY - document.getElementById("divImage").offsetTop;
}
//Now manually trigger the callback with x and y value
var arg = x.toString() + ":" + y.toString();
eo_Callback("Callback1", arg);
}
You will then be able to use such code in the server side to get back x and y:
Code: C#
string[] cords = Callback1.LastTrigger.Parameter.Split(":");
int x = int.Parse(cords[0]);
int y = int.Parse(cords[1]);
Note this way you won't really get an image click event on the server side since you are not using an ImageButton server control. You will get a Callback_Execute server side event and you can carry out your logic there. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 6/30/2007 Posts: 3
|
Thx!
Still a newbe :)
Did what you wrote but there is no action in the Callback_Execute, nothing seems to happen. I try to change a lbl value with the result.
/Stefan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hey, Stefan It works for me. Several things you need to check: 1. Make sure to fill the right "divImage" with your image's ID here if you are using Firefox.
Code: JavaScript
x = e.pageX - document.getElementById("divImage").offsetLeft;
y = e.pageY - document.getElementById("divImage").offsetTop;
2. You said you were using CallBack Panel, right? So, here, make sure "CallBack1" is your CallBackPanle's ID, normall defaut it is "CallbackPanel1" for CallBackPanel control, "CallBack1" for CallBack control
Code: JavaScript
eo_Callback("Callback1", arg);
3. For server side, you can try this:
Code: C#
string[] cords = this.CallbackPanel1.LastTrigger.Parameter.Split(new char[] { ':' });
int x = int.Parse(cords[0]);
int y = int.Parse(cords[1]);
Let me know if it still does not work for you. Thanks.
|
|
Rank: Newbie Groups: Member
Joined: 6/30/2007 Posts: 3
|
It works just fine now, your support is as always excellent.
Now, one last thing (isn't it always :), the image points to a webpage which reads a picture from a database but it doesn't update. Is this possible or not?
<img onclick="image_click(event)" src="http://www.mysite.com/displayimage.aspx?id_images=C387BFCF-96AE-433D-8800-D1D332E5C9D6" id="IMG1" />
/Stefan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Stefan Jansson wrote:It works just fine now, your support is as always excellent.
Now, one last thing (isn't it always :), the image points to a webpage which reads a picture from a database but it doesn't update. Is this possible or not?
<img onclick="image_click(event)" src="http://www.mysite.com/displayimage.aspx?id_images=C387BFCF-96AE-433D-8800-D1D332E5C9D6" id="IMG1" />
/Stefan Thanks Stefan! Our products are not the best, but we are always doing our best to support every single product that we have, and every single client that we have. :) For your question, the image should get updated. I doubt the problem is about IE cache. Did you set different GUID string for the id_images, the long string for id_images? And did you make sure the page displayimage.aspx not allowing client cache? There are several posts I found on internet. Please have a look and see if they can fix your problem. http://weblogs.asp.net/pleloup/archive/2006/06/08/451583.aspxhttp://www.qaput.com/write-code-in-asp-net-to-show-how-to-avoid-page-from-being-cached/http://www.velocityreviews.com/forums/t109653-how-can-i-avoid-cache.htmlThanks and have a great day!
|
|