views:

140

answers:

1

I used C# to build a gallery of photos. Users can hold down shift and click to select multiple photos at once. I used the System.Windows.Forms.Control.ModifierKeys property to determine whether shift is being pressed in the OnClick event of a link button, but find that it only works in IE. In Firefox, Shift + Click opens a new window and appears to bypass the button's OnClick event. What is a good solution for getting by this?

+1  A: 

You would need to take advantage of javascript to intercept the click and prevent the default action. I would recommend looking at JQuery for doing this.

I actually did something similar in the reverse direction where I use the img replacement methodology for H1 tags to make them linkable and allow them to shift click on the image and launch the new window.

This is half coded free flow so it might take some tweaking but it would be similar to

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $('img.selectable').mouseup(function(e) {

            if (e.ctrlKey || (!$.browser.msie && e.button == 1) 
                            || ($.browser.msie && e.button == 4)) {

                //middle mouse button or ctrl+click 
                //(need to lookup values for shift)
                //do something meaningful

            }
            else {
                //normal left click

            }
        })
        .click(function(e) { e.preventDefault(); });
    });                   
</script>
Chris Marisic