dynamically created RadMenu OnClick delegate doesn't fire

2 posts, 0 answers
  1. Meaning Of Lights
    Meaning Of Lights avatar
    24 posts
    Member since:
    Dec 2007

    Posted 20 Apr 2008 Link to this post

    Hi,

    I cant work out how to make dynamically created menu's postback?

    <snippet of code that demonstates the problem>

     protected void Page_Load(object sender, EventArgs e)
        {
            LoadEditMenu();
        }


        protected void LoadEditMenu()
        {
            try
            {

                RadMenu radmenu = (RadMenu)this.FindControl("RadMenu2");

                RadMenuItem mnuItem = new RadMenuItem();
                mnuItem.Text = " Open Me";
                mnuItem.CssClass = "White";
                radmenu.Items.Add(mnuItem);

                RadMenuItem mnuSubItem = new RadMenuItem();
                mnuSubItem.Text = "Settings";
                mnuSubItem.CssClass = "White";
                mnuItem.Items.Add(mnuSubItem);

                mnuSubItem = new RadMenuItem();
                mnuSubItem.Text = "Delete";
                mnuSubItem.CssClass = "White";
                mnuItem.Items.Add(mnuSubItem);

                mnuSubItem = new RadMenuItem();
                mnuSubItem.Text = "Print";
                mnuSubItem.CssClass = "White";
                mnuItem.Items.Add(mnuSubItem);



                radmenu.ItemClick += new RadMenuEventHandler(this.RadMenu_ItemClick);

                 //In the real web app, controls get loaded at runtime
                //ctrl.Controls.Add(radmenu);

            }
            catch
            { }

        }

        protected void RadMenu_ItemClick(object sender, RadMenuEventArgs e)
        {

            RadMenuItem ItemClicked = e.Item;
          
            Response.Redirect(ItemClicked.Text.ToString() + ".aspx");
        }

    </snippet>

    My RadMenu_ItemClick method never gets invoked!

     In the article (http://www.telerik.com/DEMOS/ASPNET/Menu/Examples/Programming/ServerEvents/DefaultCS.aspx) you assign the delegate in InititalizeComponent,eg:

     private void InitializeComponent()
            {
                this.Menu1.ItemClick += new RadMenuEventHandler(this.Menu1_ItemClick);




    How can I do this for dynamically created menus that sit inside dynamically created user controls??

    I've read the doco's and its something I I feel should be documented here: http://www.telerik.com/demos/aspnet/Menu/Examples/Programming/DynamicCreation/DefaultCS.aspx


    Kind regards,

    Jeremy

    www.JeremyThompson.net
  2. Meaning Of Lights
    Meaning Of Lights avatar
    24 posts
    Member since:
    Dec 2007

    Posted 21 Apr 2008 Link to this post

    Solution
    ===============

    If you have a control on the page with validators (eg the Login control), thats one cause that can prevent postback :)
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top