Dear Team
I am trying to migrate an old application which uses Infragistics 2011 controls to the new version. Therefore I have to migrate the old menu controls to the new WebDataMenu. Unfortunately, the old tag property that could be used for the MenuItems has not been replaced by an alternative.
I need to pass some additions information to the Client. As the DataItem property is not written to the HTML stream, I tried the Attributes collection, which, according to the documentation, is written to the HTML stream. But in reality it isn't. at least I don't see the data tag in the resulting HTML:
DataMenuItem item = new DataMenuItem();item.Attributes.Add("data-tag", tag);
Which leaves me with the only (but really ugly) Workaround to set the ToolTip (which will be rendered as a Title tag) or as a CSS class.
Is it really true that there is no other way?
Kevin
Hello Kevin,
The approach you are using should work just fine. I've attached a small sample where I verified this works.
To determine why this isn't working for you could you please provide me with the build number you are using for the Infragistics controls along with what sort of item the tag entry would be?
Hi Jason,
Thanks a lot, I think I found the issue:
I found out, that after the Initial page load, the attributes are present in my HTML. However, after a postback (ViewState is enabled), the menu is still appearing, but the attributes seem to be lost. So it Looks like as if the attributes are not being stored in the ViewState - is that right? Is there any way to include that?
Thanks a lot
Hi Kevin,
To resolve this issue set the Attribute for the item after you add the item to the WebDataMenu control:
if (!IsPostBack){ DataMenuItem item1 = new DataMenuItem { Key = "Item1", Text = "Item1" }; menu1.Items.Add(item1); item1.Attributes.Add("data-tag", "Item 1 tag");}
The DataMenuItems have an internal property called IsTrackingViewState that is set to false by default when the menu item is instantiated. This property only gets set to true when it is added to a parent control that is currently tracking ViewState. This works fine in most cases, however Attributes works a little different internally. In the setter for Attributes there is a check to see if IsTrackingViewState is true at the time you are setting the property. If this is false at that time, then the values you set never get added to the ViewState bag. By adding the item to the collection first IsTrackingViewState gets set to true and the property gets properly serialized.
Please let me know if you have any questions or concerns about this approach.
Does my latest approach resolve the issue of Attributes not appearing after a postback in your application?