views:

312

answers:

4

I have a requirement to produce a Web User Control (in C#) which will exhibit different behaviour when clicked depending on whether the shift (or control) key is pressed at the time. The control itself will contain an ImageButton and/or Hyperlink.

Is this possible?

Basically, if the logged in user is an Admin then I need to allow them access to update the associated URL. I don't want to have a separate page for this admin as it will cause confusion.

Thanks in advance

+1  A: 

How about here?

"To implement the Ctrl / Alt / Shift detection, you can use the properties event.ctrlKey, event.altKey, event.shiftKey and the deprecated Navigator-specific property event.modifiers."

Marc Gravell
I did find some Javascript attempts but nothing that has worked so far. The code on the link you provided it different though so i'll give it a bash - cheers
DilbertDave
+1  A: 

Your control needs to emit some javascript to detect what keys are being pressed when it is clicked on.

Here is a primer from w3schools on events, here is a list of events of the window object you can listen to (such as onkeydown for keyboard presses).

matt b
My previous attempts at Javascript to solve this have been unsuccessful, maybe due to me wiring it up incorrectly. I'll put this together with Marcs link and see where that gets me. +1
DilbertDave
If that's the case, you might want to just post what didn't work for you so we can help with that!
matt b
It's so hacked about I junked it! I'll see how I go with a fresh start and post back here either way.
DilbertDave
+1  A: 

I'd discourage this as it will get you into serious trouble with different browser versions.

As long as you aren't targeting one browser explicitly you'll be doing maintenance work for various browsers all the time.

A way around this is to find a supported Javascript library like jQuery that supports this behavior and let the maintainers of that library care about browser compatibility (You still need to update that library then..)

Tigraine
Cross browser compatibility would be a concern but I have zero experience with JQuery.
DilbertDave
I noted jQuery just as an example. There are many different Javascript frameworks out there
Tigraine
A: 

Well the 'powers' have decided that the Shift/Ctrl + Click approach was too clunky.

After a brainstorming session we have decided to go down the route of displaying a small 'Edit' button next to the control. This will only be visible for Administrator users and I've pulled it together in about two hours.

Thanks for taking the time to provide your input.

Can someone with a high rep please close this question for me - thanks.

DilbertDave