This is a migrated thread and some comments may be shown as answers.

Right click context menu for a text field!

6 Answers 401 Views
Input
This is a migrated thread and some comments may be shown as answers.
Vithiya
Top achievements
Rank 1
Vithiya asked on 19 Aug 2008, 08:27 PM
I need to pop up a context menu when the user right clicks in a text box. How can I make that happen? The reason I need to do this is to provide the user a mechanism how they can select pre-formated words to fill the text box.

Thanks!
vithiya

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Aug 2008, 11:27 AM
Hello Vithiya,

You can try the following code using which a ContextMenu will pop up on rightclicking the RadTextBox.
aspx:
<telerik:RadTextBox ID="RadTextBox1"  runat="server" onmousedown="showMenu(event);"
</telerik:RadTextBox > 

js:
<script type="text/javascript" > 
function showMenu(e) 
        { 
     alert(event.which); 
       if(event.button==2) 
       { 
     
            var contextMenu = $find("<%= RadContextMenu1.ClientID %>"); 
             
            if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget))) 
            { 
                contextMenu.show(e); 
            } 
             
            $telerik.cancelRawEvent(e); 
             
       } 
       return false; 
        } 
</script > 

Thanks
Princy.
0
Vithiya
Top achievements
Rank 1
answered on 21 Aug 2008, 07:36 PM
Thanks for the sample code Princy. It works except the right click event for IE does not get cancelled. I get the context menu and on top of that I get the IE right click menu as well. How can I suppress that?

Thanks!
vithiya
0
Missing User
answered on 22 Aug 2008, 01:13 PM
Hello Vithiya,


You can disable the browser context menu for an element in your DOM with the following JavaScript:


        <telerik:RadTextBox ID="RadTextBox1"  runat="server" oncontextmenu="return false;" onmousedown="return showMenu(event);">
        </telerik:RadTextBox >


Kind regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Vithiya
Top achievements
Rank 1
answered on 22 Aug 2008, 02:34 PM

Thanks Princy. But still no luck. I keep getting the IE right click menu no matter what. Here is what I have in my code. I do have this textbox wraped in an Ajax Panel. Does that cause any issues?

<

telerik:RadTextBox ID="txtMessage" Runat="server" Height="90px"

TextMode="MultiLine" Width="400px" AutoPostBack="True"

oncontextmenu="return false;" onmousedown="return ShowMenu(event);">

</telerik:RadTextBox>

function

ShowMenu(e, control)

{

if(e.button==2)

{

storeCaretPosition = document.selection.createRange();

controlcontext = control;

var contextMenu = $find("<%= mnuInsertKeyword.ClientID %>");

contextMenu.show(e);

$telerik.cancelRawEvent(e);

}

return false;

}

Thank you!
vithiya

0
Missing User
answered on 22 Aug 2008, 03:05 PM
Hello Vithiya,


Attached, please find a small and running project showing the needed approach.



Kind regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Vithiya
Top achievements
Rank 1
answered on 22 Aug 2008, 03:58 PM
Thanks for your help. I had the exact same code in my project and it did not work as expected. The only difference was that I had the textbox inside an ajaxpanel. Anyway, I changed the code as below and that works.

<

telerik:RadTextBox ID="txtMessage" Runat="server" Height="90px"

TextMode="MultiLine" Width="400px" AutoPostBack="True"

oncontextmenu="return ShowMenu(this);" >

</telerik:RadTextBox>

function

ShowMenu(control)

{

storeCaretPosition = document.selection.createRange();

controlcontext = control;

var contextMenu = $find("<%= mnuInsertKeyword.ClientID %>");

contextMenu.show(event);

return false;

}

Thank you!
Vithiya

Tags
Input
Asked by
Vithiya
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Vithiya
Top achievements
Rank 1
Missing User
Share this question
or