XY coordinates after clicking a button

Just in case someone interested by this tip.

I have on a page a server image button linked to a click event. This button has indeed two different functions, one to go back to the homepage, the other to go to another page.

For different reasons, I didn't want to use an image map to make the distinction between my two embedded actions.

The trick I used is quite simple but works well, and should work also with more than 2 buttons.
In the server click event I just test the coordinates using Request.Form("Nameofmybutton.x") for the horizontal position and Request.Form("Nameofmybutton.y") for the vertical position

If CInt(Request.Form("Mybutton.x")) > 83 Then

  Response.Redirect("~/Email.aspx")

Else

   Response.Redirect("~/Default.aspx")

End If

UPDATE:

I didn't know also that you can use the X or Y argument like this with a server button. Thanks Sergio:

If e.X>83 then ....

Cool ;-)

 

4 Comments

  • Why couldn't you use the click event. The Click event of the ImageButton has the "e" argument of type ystem.Web.UI.ImageClickEventArgs, so you could do:

    if e.X > 83 Then ....

  • Why couldn't you use a map? Or two images? What about users who use keyboard to navigate (like me)? How exactly are they supposed to send you an e-mail?

  • Jerry I don't use two images because I already have enough images to manage on the screen. I change the color scheme, so obviously the images, 4 or 5 times.

    Of course I understand your point about keyboard but this project is a pilot done without any accessibility in mind. This will be done in the production phase.

  • Sergio thanks for the info ;-)

Comments have been disabled for this content.