I am brand new to the telerik controls so this my be very simple.
I have created a context menu that will open anywhere in the document when text is selected. The text that is selected will be used in the context menu to replace the text of a few items that have [Selection] in their text.
All of this is working the problem I am having is getting the selection text when the user clicks on a menu item and a postback occurs. Is this possible?
<script type="text/javascript">
function getSelText() {
var txt = '';
if (window.getSelection)
return window.getSelection();
else if (document.getSelection)
return document.getSelection();
else if (document.selection)
return document.selection.createRange().text;
else
return new String("");
}
function onClientShowingHandler(sender, eventArgs){
var cancel = (getSelText().length == 0);
eventArgs.set_cancel(cancel);
if (!cancel) {
var selection = getSelText();
sender.set_clientState(selection);
var items = sender._getAllItems();
for (var i = 0; i < items.length; i++) {
items[i].set_text(items[i].get_text().replace("[Selection]", selection));
}
}
}
</script>
<telerik:RadContextMenu ID="RadContextMenu1"
OnClientShowing="onClientShowingHandler"
OnItemClick="RadContextMenu1_OnItemClick"
CollapseAnimation-Type="None" ExpandAnimation-Type="None" runat="server">
<Targets>
<telerik:ContextMenuDocumentTarget />
</Targets>
<Items>
<telerik:RadMenuItem Text="[Selection] is a Manufacturer" Value="Manufacturer" />
<telerik:RadMenuItem Text="[Selection] is a Vendor" Value="Vendor" />
<telerik:RadMenuItem Text="Copy" />
</Items>
</telerik:RadContextMenu>