Below is a simple example of what I'm trying to get to work. I've put the radMenu and a "Build Context Menu" button inside of an Atlas UpdatePanel. My theory is that once I get the button to update the context menu asynchronously then I can hide the button and fire it from my Javascript method.
However, I'm getting this error: "A JSONObject must begin with '{' ". I've seen forum posts with this error, but no one has posted a solution for it.
Here are two scenerios with the sample code below that create this error:
1. Click "Build Context Menu" to add a menu item using Atlas.
2. Right-click on one of the table cells. The new menu item is not displayed.
3. Click the "Page Post-back" button. An error page with the JSONObject error is displayed.
4. Go back to the page. Click "Page Post-back" again. It works this time, does a whole-page refresh, and now the context menu displays all of the newly added items.
1. Click "Build Context Menu" to add a menu item using Atlas.
2. Click "Build Context Menu" a second time. IE displays the JSONObject error in a message box.
Any help would be greatly appreciated.
Thank you,
Terry
Default.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="RadMenu.Net2" Namespace="Telerik.WebControls" TagPrefix="radM" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<title>Untitled Page</title>
</
head>
<
body>
<script language="javascript">
function dataCellClick(cellID)
{
var contextMenu = <%= radContextMenu.ClientID %>;
contextMenu.Show(
event);
// Stop IE from showing its context menu.
event.cancelBubble = true;
if (event.stopPropagation)
{
event.stopPropagation();
}
event.returnValue = false;
}
</script>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />
<br />
<div>
<asp:Button ID="Button1" runat="server" Text="Page Post-back" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnBuildContextMenu" Text="Build Context Menu" runat="server" />
<radM:RadMenu ID="radContextMenu" IsContext="true" ContextMenuElementID="none" runat="server">
<Items>
<radM:RadMenuItem Text="Static menu item" runat="server" />
</Items>
</radM:RadMenu>
<table>
<tr>
<td id="R1C1" oncontextmenu="dataCellClick('R1C1')">Row 1 Cell 1</td>
<td id="R1C2" oncontextmenu="dataCellClick('R1C2')">Row 1 Cell 2</td>
</tr>
<tr>
<td id="R2C1" oncontextmenu="dataCellClick('R2C1')">Row 2 Cell 1</td>
<td id="R2C2" oncontextmenu="dataCellClick('R2C2')">Row 2 Cell 2</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</
body>
</
html>
Default.aspx.vb
Partial
Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim item As New Telerik.WebControls.RadMenuItem
item.Text =
"Added in Page_Load " & Now.ToString
item.Value = Now.Millisecond
radContextMenu.Items.Add(item)
End Sub
Protected Sub radContextMenu_ItemClick(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) Handles radContextMenu.ItemClick
System.Diagnostics.Debug.WriteLine(e.Item.Text &
"clicked with value = " & e.Item.Value)
End Sub
Protected Sub btnBuildContextMenu_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBuildContextMenu.Click
System.Diagnostics.Debug.WriteLine(
"btnBuildContextMenu_Click")
Dim item As New Telerik.WebControls.RadMenuItem
item.Text = Now.ToString
item.Value = Now.Millisecond
radContextMenu.Items.Add(item)
End Sub
End
Class