Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Glitch with multiple SPMenuField & MenuTemplate objects on a Page

  Asked By: Korey    Date: Dec 14    Category: Sharepoint    Views: 1886

After testing a web part with an SPGridView and SPMenuField I
discovered a problem when I dropped two of them onto the same page.

It appeared that the menu items weren't launching properly. I soon
figured out that the MenuTemplate objects were getting mixed up
somehow. So if web part A and web part B were on a page, web part
A's menu items, when clicked, were launching with web part B's links.

Each menu was being rendered properly, but the menu items were
pointing to one web part on the page.

Here is what is rendered when using a SPMenuField and MenuTemplate:

<menu type='ServerMenu'

Here the name of the MenuTemplateId I created was "SubjectMenu".
Microsoft prepends the controls guid.

But what I found was that every menu item on the page (that my web
parts generated) was assigned a single guid string from one web part
not the unique guid from its own instance.

type="option" iconSrc="/_layouts/images/COPY.GIF"
onMenuClick="function()" text="Do Something"

Not sure why this works, but if you add the this.ID (web part's
instance guid) to the MenuTemplateId property on the SPMenuField and
the ID property on the MenuTemplate, it seems to fix this problem.

spMenuField.MenuTemplateId = "SubjectMenu_" + this.ID.ToString();
menuTemplate.ID = "SubjectMenu_" + this.ID.ToString();

There is a remote chance that this would be a problem for most
people, but stranger things have happened.



No Answers Found. Be the First, To Post Answer.