Logo 
Search:

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: 1763

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'
id="ctl00_m_g_c8b64cec_2c98_47fb_b462_f49075939127_SubjectMenu">...</m
enu>

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.

<ie:menuitem
id="ctl00_m_g_1c7b0d0c_3a5c_4fdc_8067_4b9145029ae2_ctl00"
type="option" iconSrc="/_layouts/images/COPY.GIF"
onMenuClick="function()" text="Do Something"
menuGroupId="2147483647"></ie:menuitem>

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.

IE:
spMenuField.MenuTemplateId = "SubjectMenu_" + this.ID.ToString();
and
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.

Share: 

 

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