Hi!
I'm trying to write a context menu control,for the reason to add context menu item dynamically!I wrote a web form page to invoke the control radcontextmenu.but when i click the href,I get a error:"Microsoft JScript runtime error: Object doesn't support this property or method"
web form page:
web control form(contextmenu.ascx)
web control form cs(contextmenu.ascx.cs)
contextmenu.js
Any idea about what is wrong?
Thanks.
I'm trying to write a context menu control,for the reason to add context menu item dynamically!I wrote a web form page to invoke the control radcontextmenu.but when i click the href,I get a error:"Microsoft JScript runtime error: Object doesn't support this property or method"
web form page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication1.WebForm4" %> |
<%@ Register TagPrefix="CM" TagName="contextmenu" Src="~/contextmenu.ascx" %> |
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> |
<!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> |
</head> |
<body> |
<form id="form1" runat="server"> |
<script type="text/javascript"> |
//<![CDATA[ |
function popupMenu(item, e) { |
window.<%=contex1.ClientID%>.ShowContextMenu(item, e); |
} |
//]]> |
</script> |
<telerik:RadScriptManager ID="ScriptManager1" runat="server" /> |
<div> |
<CM:contextmenu ID="contex1" runat="server" /> |
<a onclick="popupMenu(this, event)">Click here!</a> |
</div> |
</form> |
</body> |
</html> |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="contextmenu.ascx.cs" Inherits="WebApplication1.contextmenu" %> |
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> |
<Telerik:RadContextMenu id="RadContextMenu1" |
runat="server" > |
<Items> |
<Telerik:RadMenuItem Text="Trees" /> |
<Telerik:RadMenuItem Text="Sunset" /> |
<Telerik:RadMenuItem Text="Mountains" /> |
</Items> |
</Telerik:RadContextMenu> |
using System; |
using System.Collections.Generic; |
using System.Web; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
namespace WebApplication1 |
{ |
public partial class contextmenu : System.Web.UI.UserControl |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
} |
protected override void OnPreRender(EventArgs e) |
{ |
if (!this.Page.IsClientScriptBlockRegistered(this.GetType().FullName)) |
this.Page.RegisterClientScriptBlock(this.GetType().FullName, string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", this.ResolveUrl("~/ContextMenu.js"))); |
if (!Page.IsClientScriptBlockRegistered(this.ClientID)) |
Page.RegisterStartupScript(this.ClientID, String.Format("<script language=javascript>window.{0} = new ContextMenu('{0}', {1});</script>", this.ClientID, this.RadContextMenu1.ClientID)); |
base.OnPreRender(e); |
} |
} |
} |
function ContextMenu(name, contextMenu) { |
this.Name = name; |
this.ContextMenuHandle = contextMenu; |
this.ShowContextMenu = function() { |
this.ContextMenuHandle.show(arguments[1]); //(the JScript error ) |
} |
} |
Thanks.