Use Unique Ids for MenuTemplates

This is a follow-up on my other articles on SPGridView and Menus.
This time I have discovered an anoying thing about MenuTemplates.

The thing is, if you use two MenuTemplates on the same page with same ids they behave like they are the same template.
To demo this, I used the code from this post and did a copy/paste (yes I know you shouldn´t do that) and made the new control go against an announcements list instead of a contacts list.

I used the two controls on the same page and this is what happened:

 

image

This is the same code as in the ListContacts.ascx control but I I changed the text to “Delete announcement”.
And, now when I add the two usercontrols on the same page, this is what happens.

image

As you can see the text on the menu on my ListAnnouncements.ascx control gets the value from the other, ListContacts.ascx control.
After some digging I discovered that if two MenuTemplates with same Ids exists on the same page, they will behave as one. This of course happened to me because I did a copy/paste, but if you look at the sourcecode of MenuTemplate you see this:

image

It doesn´t implement INamingContainer which ensures unique Ids, that´s gotto be a bug.

So, I changed the Id of the MenuTemplate like:

image

…and

image
So , in summary. Use unique Ids with your menu templates.

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: