Welcome Guest Search | Active Topics | Sign In | Register

Callback and eventargs from controls Options
Stefan Jansson
Posted: Saturday, June 30, 2007 5:46:22 AM
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
eo_support
Posted: Saturday, June 30, 2007 7:01:43 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
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
Stefan Jansson
Posted: Saturday, June 30, 2007 9:24:02 AM
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
eo_support
Posted: Saturday, June 30, 2007 12:46:00 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
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.
Stefan Jansson
Posted: Sunday, July 1, 2007 12:09:36 AM
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
eo_support
Posted: Sunday, July 1, 2007 9:23:19 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
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.aspx
http://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.html

Thanks and have a great day!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.