Hi,
I am creating Rad Menu dynamically. Following is the code. Even I tried following code in Page_Load().
But still its not working...
Why? Can anyone help me?
public partial class _Default : System.Web.UI.Page
{
RadMenu menu;
protected override void CreateChildControls()
{
base.CreateChildControls();
menu = new RadMenu();
menu.ID = "radmenucontrol";
menu.Items.Add(new RadMenuItem("Google", "http://www.google.com"));
menu.Items.Add(new RadMenuItem("Google1", "http://www.google.com"));
menu.Items.Add(new RadMenuItem("Google2", "http://www.google.com"));
menu.Items.Add(new RadMenuItem("Google", "http://www.google.com"));
menu.Items.FindItemByText("Google").Items.Add(new RadMenuItem("Yahoo", "Default.aspx"));
menu.Items.FindItemByText("Google").Items.Add(new RadMenuItem("Yahoo1", "Default.aspx"));
this.Controls.Add(menu);
menu.ItemClick += new RadMenuEventHandler(menu_ItemClick);
}
void menu_ItemClick(object sender, RadMenuEventArgs e)
{
Response.Redirect("http://www.google.com");
}
}
5 Answers, 1 is accepted
I have found that you have set the NavigateUrl property which effectively disables the postbacks. Please check the following forum link which describes the possible solution for this.
ItemClick event not firing
Thanks,
Princy.
I followed thes steps written in following discussion
ItemClick event not firing
But it still not firing the event.
I got the where the problem is but dont know how to solve. Please help me!!!!
Note: I am working in SharePoint ( WSS 3.0 )
I am using "RadMenu.NET2" dll of version 4.4.6.0 which I placed in GAC.
I want to use this in a web part. But for example purpose I created one asp.net application and I am creating RadMenu dynamically.
The Revised code is
public partial class _Default : System.Web.UI.Page
{
RadMenu menu = new RadMenu();
protected void Page_Init(object sender, EventArgs e)
{
menu.ItemCreated += new RadMenuEventHandler(menu_ItemCreated);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
//menu = new RadMenu();
menu.ID = "radmenucontrol";
menu.Items.Add(new RadMenuItem("Google", "http://www.google.com"));
menu.Items.Add(new RadMenuItem("Google1", "http://www.google.com"));
menu.Items.Add(new RadMenuItem("Google2", "http://www.google.com"));
menu.Items.Add(new RadMenuItem("Google", "http://www.google.com"));
menu.Items.FindItemByText("Google").Items.Add(new RadMenuItem("Yahoo", "Default.aspx"));
menu.Items.FindItemByText("Google").Items.Add(new RadMenuItem("Yahoo1", "Default.aspx"));
menu.ItemClick += new RadMenuEventHandler(menu_ItemClick);
this.Controls.Add(menu);
}
void menu_ItemCreated(object sender, RadMenuEventArgs e)
{
e.Item.Attributes["NavigateUrl"] = e.Item.NavigateUrl;
e.Item.NavigateUrl = "";
}
void menu_ItemClick(object sender, RadMenuEventArgs e)
{
Response.Redirect(e.Item.Attributes["NavigateUrl"].ToString());
}
}
But it does not work. So what I tried is, I registered reference of "RadMenu.NET2" in my .aspx page like
<%@ Register TagPrefix="rad" Namespace="Telerik.WebControls" Assembly="RadMenu.NET2" %>
And Added one radmenu control at design time. Added some Items and add menu click event also and it works. The menu click event is firing...
And I found that when I create RadMenu control dynamically it does not create following javascript code in html. I checked it in ViewSource.
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
and is also not creating two hidden controls
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
But when I create RadMenu at design time, it creates this hidden control and Javascipt also...
Can u please help me, how to solve this????
Thanks
Savan
I tested the provided code and Item_Click event is firing, I've attached my test project based on your code, so please download it and give it a try.
All the best,
Yana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thanks.
The problem was , I dont have added script manager in form.
Thanks again, for your support
Savan
One another problem is there now.
The code that you have given works very fine.
When I add same code in SharePoint web part, it works there aslo.
But When I create a web control, add that web control in master page, then its not working, by registering that control like
<%@ Register TagPrefix="RadMenuControl " Namespace="RadMenuControl" Assembly="RadMenuControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f47633eb40d2fe0d" %>
When I do this, control comes in page, but event is not firing. I have a web part on the same page, with same code, and there event is firing.
Can you tell me why?
Thanks
Savan