Problem with client event handlers on menu in UpdatePanel

2 posts, 0 answers
  1. Scott R
    Scott R avatar
    63 posts
    Member since:
    Jun 2008

    Posted 26 Jun 2008 Link to this post

    I have a RadMenu that exists in a MasterPage. The master page adds a client event handler to the OnClientItemClicking event. Here's the code:

        <script type="text/javascript">  
            function PageLoad()  
                var menu = $find("<%= MasterMenuInner.ClientID %>");  

    The PageLoad() function is called by the body "onload" event.

    The content page also needs to handle the OnClientItemClicking event. Here's the code for that:

            function MenuItemClickingConfirmDelete(sender, args)  
                 var itemValue = args.get_item().get_value();  
                 if (itemValue == 'Delete')  
                    if (confirm('Delete this invoice?'))  
            function InvoiceListPageLoad()  
                var menu = $find("<%= Master.MasterMenu.ClientID %>");  
                if (menu)  
                    alert("<%= Master.MasterMenu.ClientID %> not found!");  

    The "InvoiceListPageLoad()" function is also called by the body "onload" event.

    So, everything works fine on the initial page load. Both event handlers fire as expected. Great.

    The problem starts when the menu (on the master page) is updated. During an AJAX postback, I enable/disable some buttons. The menu is inside an UpdatePanel. The menu updates fine, but all client event handlers are "lost". I guess they are not part of the control state or view state. Obviously the body "onload" event doesn't fire after an AJAX postback.

    I tried using the following code to re-register the event handlers after an AJAX postback:

    ScriptManager.RegisterStartupScript(this, this.GetType(), "startup", "InvoiceListPageLoad();", true);

    Unfortunately, I always get the alert box that says "ctl00_MasterMenuInner not found!"

    How do I register a client event handler after an AJAX postback?
  2. Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 26 Jun 2008 Link to this post

    Hi Scott R,

    You could just set the OnClientItemClicking property of RadMenu to "MenuItemClicking". Your event handler will subscribe after ajax updates. The other option is to use the Sys.Application events instead of <body onload>.

    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top