locked
Use a menu control in updatepanel RRS feed

  • Question

  • User-1023711300 posted

    that occurs a javascript error when click another tab "0.cells" is null or not an object.

    who can help me? thanks.

    Thursday, January 4, 2007 4:47 AM

All replies

  • User961349301 posted

    The menu control is not compatible with partial-page updates and can't be used inside a UpdatePanel.

     

    Thursday, January 4, 2007 4:56 AM
  • User-1023711300 posted
    what can i do if i want to implement this function?thx.
    Thursday, January 4, 2007 5:48 AM
  • User646164520 posted
    Could you run this in JS debugger and post a snippet of affected JS.. I vaguely remember dealing with this issue and it might allow us to see what is exactly happening
    Thursday, January 4, 2007 6:14 AM
  • User646164520 posted

    did quick google

    and found e.g. this 

    http://forums.asp.net/thread/1485169.aspx

     

    Thursday, January 4, 2007 6:28 AM
  • User-1023711300 posted

    thanks for your information, i read a blog and using this method it works well.

    http://mcosier.blogspot.com/2006/12/0cells-is-null-or-not-object-aspnet-20.html

    but i have a problem that:

    it seems that using AsyncPostBackTrigger can't change the StaticSelectedStyle after i clicked another menuitem?

    thanks.

    Thursday, January 4, 2007 9:48 PM
  • User-2050958843 posted

    I've been using this piece of javascript to go around the menu problem:

    var oldMenu_HideItems = Menu_HideItems;
    	
    if(oldMenu_HideItems)
    {
    	Menu_HideItems = function(items){
    	if (!items || ((typeof(items.tagName) == "undefined") && (items instanceof Event))) { items = __rootMenuItem; }
    	if(items && items.rows && items.rows.length == 0){ items.insertRow(0); }
    		return oldMenu_HideItems(items);
    	} 
    }
    
     
    I got it from the asp:menu javascript code and I hook it to "patch" the problem.
    Adding it to a page where a menu resides makes the javascript error go away. 
    Friday, January 5, 2007 6:46 AM
  • User-1016791496 posted

    This one works great for me.

    Thank you very very much.[:D]

     

    Great

    Thursday, January 11, 2007 3:16 AM
  • User699237567 posted
    it is working..  [:)] Thank you for your great solutions.
    Thursday, February 22, 2007 8:38 PM
  • User-978539694 posted

    thanks t0y[:D]

    i tryed  it. and i dident give that error.

    thanks again.

    Monday, March 5, 2007 7:57 AM
  • User191915843 posted

    Dear sir

    can you please tell me where to put this code in what event, name of the function it is very imp.

     thank you,

    please advise what to do.

    Sunday, March 11, 2007 1:50 PM
  • User-968699102 posted
    This piece of Javascript has saved me hours of googling! Awesome work buddy and thanks heaps!
    Sunday, May 13, 2007 11:21 PM
  • User555306248 posted

    See for more info , which controls are not compatable with UpdatePanel

    http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx

    Monday, May 14, 2007 5:26 AM
  • User1712261073 posted

    I cannot figure out how to use this fix. I put this script in my page and I'm still getting the 0.cells is nothing error.

     

    How do I hook this up?

     

    Thanks!

    Tuesday, May 29, 2007 9:51 PM
  • User555306248 posted

    Have you tried the solution that t0y  provided..

    It's working..[:)]

    Tuesday, May 29, 2007 11:21 PM
  • User1712261073 posted

    Have you tried the solution that t0y  provided..

    It's working..Smile

     

    I have tried, but it has no affect on my menu within my update panel. All I've done is stuck the script betweeen 2 script tags. Is there anything special I need to do in order to wire it up to my menu?

     

    I'm just confused about how it works.

     

    Thanks.

    Wednesday, May 30, 2007 7:12 AM
  • User-2050958843 posted

    Hmm... I was almost sure I'd get email notifications for this thread. That's why I never answered.

    If you're having trouble with my "hack" try inserting the code outside any updatepanels you may have. If you happen to use a masterpage try using it there but there's the possibility that it will give errors in pages where you're not using Menu.

    In complicated pages the updatepanels and javascript may become rather complex. The trick is to make sure my code runs in pages where the asp:menu client code script resides.

    Good luck,

    --t0y 


     

     

    Thursday, June 21, 2007 4:54 PM
  • User-1497785059 posted

     Hi,

       Well I tried pasting your hack inside a script tag in my page but the problem still persists. I'm sorry if I'm not getting any simple point, but still its not working for me. Please tell me is this code needs to pasted inside some function? I just pasted AS-IS, with no modifications or additions. But I felt that this should be part of some function.

    Also when I did a view source of my page, I did't see any other javascript code generated like that one, so that it will override it.

    Now this problem does goes off if I place my menu control outside the update panel. I know that menu control is not supported by updatepanel, but the reason I shifted it into the updatepanel, is that I have a function in the code behind which will change the Image of the selected menu item. If I remove the menu control from updataepanel, the Image won't change,even if the function called.( And obviously it won't !! ). But if its inside the updatepanel then it will change, but will give the 0.cells javascript error.

     

    Can you please help me little more...

     



     

    Friday, June 22, 2007 8:22 AM
  • User-2050958843 posted

    The javascript it overrides is, IIRC, added as an external link in the head section of the page. You can easily see it if you use firefox+firebug and checking where the error occurs.  

    It's kind of hard trying to explain this because the error only happens under some circumstances and only in those I needed the script.

    I may be more helpful if I could look at some simplified version of your page that exhibits this error. If it's too much to post here, send it to my email and I'll have a look when I have the time.
     

    Friday, June 22, 2007 10:12 PM
  • User555306248 posted

    Have you got any solution ?

    Have you seen links posted in the forums ?

    Friday, June 22, 2007 11:46 PM
  • User-1497785059 posted

     Hi,

        I have checked the links in this forums but still not reached any solution.

     


     

    Monday, June 25, 2007 1:20 AM
  • User-1497785059 posted

     Hi t0y,

        Thanks a lot for your reply. Your script patch work perfectly. Actually I added the script tag to the head section of the page, but when I saw your example, I moved it inside the body tag and it works so fine [:D].

     

    Thanks once again for your help.

     


     

    Tuesday, June 26, 2007 2:20 AM
  • User555306248 posted

    Thats nice buddy

    Tuesday, June 26, 2007 2:26 AM
  • User460342110 posted

    Exellent it is working!! Thanks for the script!!

    Monday, July 23, 2007 2:28 PM
  • User1203329084 posted

    Hi,

    put the above mentioned code in Javascript function

    call the same on <body onload="YourfunctionName()">

    Regards

    Noor

    Tuesday, July 31, 2007 11:11 AM
  • User-1640925417 posted

    Thanks everybody for the helpful discussion so far.  Since this is working for others, I must be doing something wrong.  I am a complete novice when it comes to javascript.

    I have a tab menu defined on a master page.  The body tag surrounding the master page form looks like this:

        <body onload="initialScripts()" >

    I used to call a different javascript function there, which I still need, so I organized these into two separate functions and call them from one like this (in a .js file):

        function initialScripts()
        {
            tableruler();
            menufix();
        }
        onload='initialScripts()';

     ...where menufix() includes the code from this thread and tableruler does something else.  Would someone let me know if I'm going about this the wrong way please?  Thanks!
     

    Thursday, September 13, 2007 6:24 PM
  • User555306248 posted

    var oldMenu_HideItems = Menu_HideItems;

    if(oldMenu_HideItems)
    {
    Menu_HideItems = function(items){
    if (!items || ((typeof(items.tagName) == "undefined") && (items instanceof Event))) { items = __rootMenuItem; }
    if(items && items.rows && items.rows.length == 0){ items.insertRow(0); }
    return oldMenu_HideItems(items);
    }
    }

     
     
    Friday, September 14, 2007 12:49 AM
  • User-1640925417 posted

    Yes, that is the code I put inside the function menufix() in my .js file.  I wasn't missing that part.  :-)

    It seems that I have to interrupt the browser to make the error occur.  If I wait patiently for it to finish posting back, rendering, etc. I never get the error.  Has anyone else had a similar experience?
     

    Friday, September 14, 2007 10:00 AM
  • User1867197125 posted

    Any best solution about it ?

    What say Microsoft about this issue ???

    Thanks.

    Thursday, September 27, 2007 10:09 AM
  • User-1962552405 posted

    It's working. Thanks a lot.

    Although this problem only exist in IE, but it seems the WebResource.axd was not run the right client code.

    Hope it will be correct next version. 

    Saturday, December 29, 2007 8:20 AM
  • User-1222164807 posted

    this is very useful and working fine,can u explain this code for me

     send this to my mail if have time

    hajaworld@yahoo.co.in 

    Wednesday, February 27, 2008 1:48 AM
  • User-817894544 posted

    My requirement is  as follows :

       In my AJAX enabled page i have a XML based ASP.NET menu. When i click a menu item through MENU ITEM CLICK event my page is getting refreshed???

    Actualluy When i click menu item i am calling standalone CLASS file(not a WEBPAGE) which resides in APP_CODE folder, checking somethings  with database data and atlast i am generating SUCCESS javascript alert or ERROR alert in a arraylist object.

    I dont want  my page to be refreshed?????? i just want SUCCESS or ERROR alert message asyncronously???

    Code is as below: 

    Thanks in advance.....

    protected void FileMenu_MenuItemClick(object sender, MenuEventArgs e)

    {

    if
    (FileMenu.SelectedItem.Value == "I_129 Form")

    {

    I_129Form I129Form = new I_129Form(); //calling class code which checks some functionality from database data and generates ARRAYLIST object

    ArrayList list=I129Form.FillI_129Form();

    ////// this arraylist  i'm formatting and displaying as below

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OK", "<script>alert('Success !');</script>");

    } }

    Wednesday, May 28, 2008 12:47 PM
  • User548000170 posted

     Thank you t0y!

    Perfect solution!

    I use Menu in the UpdatePanel in the custom server webcontrol.

    I've insert your code in the OnPreRender method this way:

     

    protected override void OnPreRender(EventArgs e)
    {
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("<script type='text/javascript'>");
    sb.AppendLine("var oldMenu_HideItems = Menu_HideItems;");
    sb.AppendLine("if(oldMenu_HideItems)");
    sb.AppendLine("{");
    sb.AppendLine(" Menu_HideItems = function(items)");
    sb.AppendLine(" {");
    sb.AppendLine(" if (!items || ((typeof(items.tagName) == 'undefined') && (items instanceof Event))) { items = __rootMenuItem; }");
    sb.AppendLine(" if(items && items.rows && items.rows.length == 0){ items.insertRow(0); }");
    sb.AppendLine(" return oldMenu_HideItems(items);");
    sb.AppendLine(" }");
    sb.AppendLine("}");
    sb.AppendLine("</script>");
    Page.ClientScript.RegisterStartupScript(typeof(string), "fixMenuInUpdatePanel", sb.ToString());

    base.OnPreRender(e);
    }
      
    Sunday, August 31, 2008 4:48 AM
  • User548000170 posted

    My requirement is  as follows :

       In my AJAX enabled page i have a XML based ASP.NET menu. When i click a menu item through MENU ITEM CLICK event my page is getting refreshed???

    Actualluy When i click menu item i am calling standalone CLASS file(not a WEBPAGE) which resides in APP_CODE folder, checking somethings  with database data and atlast i am generating SUCCESS javascript alert or ERROR alert in a arraylist object.

    I dont want  my page to be refreshed?????? i just want SUCCESS or ERROR alert message asyncronously???

     

    The solution for you is Page Methods. Remove the OnClick event habdler from the MenuItem and handle the click event on the client:

      

    MenuItem mnuColumns = new MenuItem("Columns", "", "", "javascript:callMyPageMthod(); return false;"); 
     
     And call your PageMethod from the callMyPageMethod() javascript function setting the onComplete handler.
    function myOnCompleteHandler(result)
    {
        alert(result); 
    } 
    Sunday, August 31, 2008 5:01 AM
  • User393413966 posted

    solved my issue

    add this line in page load event

    ScriptManager.RegisterStartupScript(Me, GetType(String), "FixMenu", "FixMenu();", True)

    <script type="text/javascript">

    function FixMenu()

    {if (typeof(IsMenuFixed)!='undefined') return;

    if (!window.Menu_HideItems) return;

    window.OldMenu_HideItems=window.Menu_HideItems;

    window.Menu_HideItems=function(items)

    { try

    { OldMenu_HideItems(items); }

    catch(ex){

    if (items && items.id)

    { PopOut_Hide(items.id); }

    }

    }

    IsMenuFixed=true;

    }

    </script>

     

     

    Monday, December 14, 2009 2:12 PM