Can the right click be captured, set a variable on the page somewhere (eg. text box), which then causes the normal postback which would occur if the left button was pressed, which can be captured by the asp.net - asp.net reads the textbox variable, and can
determine it was a right click?
You can capture the right click event in JavaScript using the oncontextmenu event. You could then call a function that sets the "variable" and causes the postback. The easiest way to cause the postback might be to force a click of a hidden button.
For example, if you wanted to capture the right click in a text box...
// JavaScript function
function RightClickJSFunction(id)
{
document.getElementById(id).value = "right click";
button1.click();
}
Obviously isn't a properly thought through solution coz I guess you wouldn't want to put the value in the same text box but I hope that gives you some ideas.
Marked as answer by mtait on May 10, 2007 01:20 PM
mtait
Contributor
2128 Points
521 Posts
Detect right-mouse click
May 09, 2007 12:47 PM|LINK
Hi - is there anyway of determining in a postback in asp.net (vb) if the right mouse button has been clicked, as opposed to just a mouse click?
Thanks, Mark
mtait
Contributor
2128 Points
521 Posts
Re: Detect right-mouse click
May 09, 2007 12:56 PM|LINK
...for example...
Can the right click be captured, set a variable on the page somewhere (eg. text box), which then causes the normal postback which would occur if the left button was pressed, which can be captured by the asp.net - asp.net reads the textbox variable, and can determine it was a right click?
Thanks, Mark
chrisoftoday
Member
263 Points
66 Posts
Re: Detect right-mouse click
May 10, 2007 10:53 AM|LINK
You can capture the right click event in JavaScript using the oncontextmenu event. You could then call a function that sets the "variable" and causes the postback. The easiest way to cause the postback might be to force a click of a hidden button.
For example, if you wanted to capture the right click in a text box...
yourTextbox.Attributes.Add("oncontextmenu", "RightClickJSFunction(this.id);")
// JavaScript function
function RightClickJSFunction(id)
{
document.getElementById(id).value = "right click";
button1.click();
}
Obviously isn't a properly thought through solution coz I guess you wouldn't want to put the value in the same text box but I hope that gives you some ideas.
mtait
Contributor
2128 Points
521 Posts
Re: Detect right-mouse click
May 10, 2007 01:28 PM|LINK
It does - thank you very much.
Is there a way to stop the context menu coming up (I'm using an update panel, and it posts back, but still shows the menu).
Thanks, Mark
chrisoftoday
Member
263 Points
66 Posts
Re: Detect right-mouse click
May 11, 2007 09:35 AM|LINK
Add return false after calling the JavaScript function
yourTextbox.Attributes.Add("oncontextmenu", "RightClickJSFunction(this.id); return false;")
chrisoftoday
Member
263 Points
66 Posts
Re: Detect right-mouse click
May 11, 2007 09:38 AM|LINK
Add return false after calling the JavaScript function
yourTextbox.Attributes.Add("oncontextmenu", "RightClickJSFunction(this.id); return false;")