Using Menu inside UpdatePanel
A previous post of mine detailed the list of ASP.Net controls that cannot be used with UpdatePanel and ASP.Net Ajax. Since I provided a fix for the validators earlier on, I've decided to try to fix the Menu, as well. And I did! At least for my problem which involved using a two level dynamic menu inside an UpdatePanel.
Here is the code:
Now all you have to do is load it at every page load:
Explanation: the error I got was something like "0.cells is null or not an object", so I looked a little in the javascript code, where there was something like " for(i = 0; i < rows[0].cells.length; i++) {" and rows[0] was null. All this in a function called Menu_HideItems.
Solution 1: Copy the entire function (pretty big) and add an extra check for rows[0]==null.
Solution 2: Hijack the function, put it in a Try/Catch block and put the bit of the original function that appeared after the error in the catch. That I did.
Here is the code:
<script>
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>
Now all you have to do is load it at every page load:
ScriptManager.RegisterStartupScript(this,GetType(),"FixMenu","FixMenu();",true);
Explanation: the error I got was something like "0.cells is null or not an object", so I looked a little in the javascript code, where there was something like " for(i = 0; i < rows[0].cells.length; i++) {" and rows[0] was null. All this in a function called Menu_HideItems.
Solution 1: Copy the entire function (pretty big) and add an extra check for rows[0]==null.
Solution 2: Hijack the function, put it in a Try/Catch block and put the bit of the original function that appeared after the error in the catch. That I did.
Comments
<p>Hey, please post new information in the comments! :)<br><br>Thank you! My only wish is that, when you find similar problems that I or anybody else has not fixed, find a fix yourself and post it somewhere where search engines can find it.</p>
SideriteHey, please post new information in the comments! :)<br><br>Thank you! My only wish is that, when you find similar problems that I or anybody else has not fixed, find a fix yourself and post it somewhere where search engines can find it.
Siderite<p>MAnnnnnnnnnnnnnn You are Awessssssssssssommeeeeee</p>
AnonymousMAnnnnnnnnnnnnnn You are Awessssssssssssommeeeeee
Anonymous<p>ok man I NEVER EVER post comments. <br><br>but you are a FUCKING GENIUS since you just solved a problem that cost me 10h already!<br><br>THX MAN</p>
Anonymousok man I NEVER EVER post comments. <br><br>but you are a FUCKING GENIUS since you just solved a problem that cost me 10h already!<br><br>THX MAN
Anonymous<p>Thanks. This was the best solution to the problem. All the others messed up my page events. Great Job!<br>Brian</p>
AnonymousThanks. This was the best solution to the problem. All the others messed up my page events. Great Job!<br>Brian
Anonymous<p>Thanks bro .....thanks a ton u reallly saved my job</p>
ankyThanks bro .....thanks a ton u reallly saved my job
anky<p>IntezaarForU.....<br><br>Thank you dude.. it works great for me :-).</p>
AnonymousIntezaarForU.....<br><br>Thank you dude.. it works great for me :-).
Anonymous<p>Very nice, thanks for the info. It works.</p>
MiladVery nice, thanks for the info. It works.
Milad<p>Thanks a lot man!! this really helps us...</p>
AnonymousThanks a lot man!! this really helps us...
Anonymous<p>If there were more guys like u...</p>
AnonymousIf there were more guys like u...
Anonymous<p>Thanks a lot! :D</p>
AnonymousThanks a lot! :D
Anonymous<p>Thanks man, just what I needed!</p>
AnonymousThanks man, just what I needed!
Anonymous<p>thanx a lot, just what i was looking for!</p>
kusithanx a lot, just what i was looking for!
kusi<p>Works like a charm...thanks!<br><br>Winger</p>
AnonymousWorks like a charm...thanks!<br><br>Winger
Anonymous