Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

asp.net - how can I a function to the drop down on right click?

Whne I right click on my screen I need to add a function to the list so that when I click on it will execute...
0
GlobaLevel
Asked:
GlobaLevel
  • 7
  • 3
  • 3
  • +4
1 Solution
 
Deepak LakkadCommented:
which type of application you are developing (Winform or Web)?

Pls. explain your requirements in detail

- Deepak Lakkad
0
 
gery128Commented:
Here is Javascript snippets that will allow you to detect right click:
function doSomething(e) {
  var rightclick;
  if (!e) var e = window.event;
  if (e.which) rightclick = (e.which == 3);
  else if (e.button) rightclick = (e.button == 2);
  alert('Rightclick: ' + rightclick); // true or false
}

Open in new window

Reference link: http://www.quirksmode.org/js/events_properties.html#button
Once detected you can add JS function to your dropdown or any other controls.
-Girish
0
 
Anurag AgarwalCommented:
GlobaLevel first note that right click is interpreted in different manner in different ways thus one script may working perfectly in IE but not in Firefox or other browser so you need to checkit


 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="rightclick.aspx.vb" Inherits="rightclick" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        var message = "hello";
        function click(e) {
            if (document.all) {
                if (event.button == 2) {
                    alert(message);
                    //Call Any other function
                    return false;
                }
            }
            if (document.layers) {
                if (e.which == 3) {
                    alert(message);
                    //Call Any other function
                    return false;
                }
            }
        }
        if (document.layers) {
            document.captureEvents(Event.MOUSEDOWN);
        }
        document.onmousedown = click;



       

    </script>
</head>
<body onContextMenu="alert('type message here'); ">
<%--Call Any other function in place of alert--%>
    <form id="form1" runat="server">
    <div >
    <h1>
    anurag_onnet
    </h1>
    </div>
    </form>
</body>
</html>

Open in new window



<script language="javascript" type="text/javascript">
        var message = "hello";
        function click(e) {
            if (document.all) {
                if (event.button == 2) {
                    alert(message);
                    //Call Any other function
                    return false;
                }
            }
            if (document.layers) {
                if (e.which == 3) {
                    alert(message);
                    //Call Any other function
                    return false;
                }
            }
        }
        if (document.layers) {
            document.captureEvents(Event.MOUSEDOWN);
        }
        document.onmousedown = click;
    </script>



used for IE and onContextMenu="alert('type message here'); " used for Firefox
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GlobaLevelAuthor Commented:
Please see attachment for clarification...it contains a screenshot that spells it all...any questions please let me know...
Send-Highlight.docx
0
 
GlobaLevelAuthor Commented:
so I need to add it to the menu that appears once the user right clicks...
0
 
Anurag AgarwalCommented:
ya once the user right click , first the above script should be activated and in the alert section add your menu scripts.
0
 
GlobaLevelAuthor Commented:
well i tried to run to select  "anurag_onnet" and send to db...but wouldnt work...any ideas..?

code below...
0
 
Bob LearnedCommented:
I have no idea what you have tried, and what problems that you are having, which makes it difficult for me to help you (if I can)...
0
 
MlandaTCommented:
This something you have to do by playing around with the windows shell...

[NOTE: Most of these examples deal with the explorer menus, not specifically that menu you are looking for... however, you may pick up some ideas from these.

http://www.extremetech.com/article2/0,2845,1838907,00.asp
http://www.extremetech.com/article2/0,1697,1838905,00.asp
http://www.tucows.com/article/1187
http://www.jfitz.com/tips/rclick_custom.html
http://sumtips.com/2011/02/hacks-to-enhance-windows-context-menu.html

Caution: Before editing your registry, it would be wise to create a system restore point by using system restore. Doing so will provide an easy method to revert back to your original configuration before you make any changes—just in case you accidentally delete or modify something that hurts your computer.
0
 
GlobaLevelAuthor Commented:
TheLearnedOne...see the link in this post for attachment...

35084099
http://35084099
0
 
Bob LearnedCommented:
I can't access that link.  What type of attachment is it?  Is it a type that you can't attach to this question?
0
 
CodeCruiserCommented:
You have selected ASP.NET as one of the zones. Do you want to add menu item to a browser's right click menu?
0
 
GlobaLevelAuthor Commented:
You have selected ASP.NET as one of the zones. Do you want to add menu item to a browser's right click menu?

>> correct...
0
 
CodeCruiserCommented:
I dont think you can do that from a website. This has to be done on the client computer. And it would be browser specific.
0
 
GlobaLevelAuthor Commented:
so I made some progress...I get how to add items to the context menu via the registry...but will the registry allow me to add items such as a program.. .exe to it?
0
 
CodeCruiserCommented:
You managed to add items to a client registry from a website?
0
 
MlandaTCommented:
I am not sure whether you can modify at applicaiton level. I have tried looking around, but cannot quite seem to find anything. However, the articles I have seen on this seem to point to using a global system hook to capture the WM_CONTEXTMENU message. Hoewever, note that Global hooks are not supported in the .NET Framework so you would presumably have to have a native DLL in C++.

To add a context menu for a certain window, we have to capture
WM_CONTEXTMENU message. I believe other vendors do this also in their
programs.

To change all the context menu in windows for a certain kind of control, we
have to set a global hook for the message. In .NET, there are two major
components of the library. The first part is a C# class library which you
use directly in your application. That class library, in turn, uses an
unmanaged C++ DLL internally to manage the system hooks directly.

Here is an article for more information and a sample. HTH.

Have a look at these articles:
http://www.codeproject.com/csharp/GlobalSystemHook.asp
http://support.microsoft.com/?id=318804

This additional info led me to this Google Search that yielded also some interesting results.
0
 
GlobaLevelAuthor Commented:
Mlanda...this is good info...but I have to create a distributed app..can I put these 'hooks' into an installer that the client can download?
0
 
MlandaTCommented:
Yes. You could create your application such that it registers the hooks when it is first run or something of the sort. Or add a custom step to the installer - though this will depend on the capabilities provided by the application you are using to create the installer.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 3
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now