dave_p_s
Jul 30 at 10:06 AM |
Hi, I'm new at this VS C# coding (having been used to C for many years) environment and so this question that I?m about to ask may be inappropriate for this forum but I?m hoping you will be able to answer the question or point me in the right direction.
All I'm trying to do is extend the CSS MenuAdapter.cs so that I can include a new Site Map Node custom attribute so in turn I can change the html generated by the MenuAdapter.cs to include a new attribute within the <a tag
i.e
Site Map Node <siteMapNode url="~/GenericPage.aspx?goto=Products" title="Products" description="Create a Fundraising Page" mid="m1" />
mid attribute assigned to the <a id= tag <a id=?m1? href="/CssAdaptersTutorial1/GenericPage.aspx?goto=SupportKnowledgeBase" class="AspNet-Menu-Link" title="Knowledge Base">Knowledge Base</a>
I then use the <a id= tag to help render my CSS rules with a little bit more control.
What I don?t know how to do is how to pull through or reference the new mid Site Map Node custom attribute within the CSS Friendly Control Adapters MenuAdapter.cs code?
Any snippets of code etc. would be much appreciated.
|
bdemarzo
Coordinator
Aug 1 at 2:12 AM |
You may have more success getting a response by posting on the CSS adapter forums at http://forums.asp.net/1018.aspx
|
dave_p_s
Aug 1 at 1:59 PM |
bdemarzo wrote: You may have more success getting a response by posting on the CSS adapter forums at http://forums.asp.net/1018.aspx
Thanks.
|
Rinze
Today at 2:12 AM
Edited Today at 2:14 AM |
I can't find a post concerning this question on forums.asp.net, so i'll post an answer here ;-).
The custom attribute isn't readily available to you on the menuitem, I think it's only available during databinding. So if it's an attribute for node selection, use it in a custom sitemap provider. If it has to be written to the output, use the MenuItemDataBound event to add it to the menuitem. In the buildItem method you use writer.WriteAttribute("id", item.PROPERTY). Because you're dealing with menuitems you have to use an existing property (correct me if i'm wrong!)
and the databinding code: protected override void OnInit(EventArgs e) { menu.MenuItemDataBound += new MenuEventHandler(BindCustomAttributes); base.OnInit(e); }
protected void BindCustomAttributes(object sender, MenuEventArgs e) { SiteMapNode sn = e.Item.DataItem as SiteMapNode; if (!String.IsNullOrEmpty(sn["mid"])) { e.Item.PROPERTY= sn["mid"]; } }
Hope this helps, rinze
|
dave_p_s
Today at 10:21 PM |
Hi Rinze, Thanks for taking a look at this for me. However I must still be missing something fundamental as I'm getting these errors when I compile
Error 3 The name 'menu' does not exist in the current context C:\Inetpub\wwwroot\CssAdaptersTutorial1\App_Code\Adapters\MenuAdapter.cs 35 17 C:\...\CssAdaptersTutorial1\ Error 4 'System.Web.UI.WebControls.MenuItem' does not contain a definition for 'PROPERTY' C:\Inetpub\wwwroot\CssAdaptersTutorial1\App_Code\Adapters\MenuAdapter.cs 44 24 C:\...\CssAdaptersTutorial1\ Error 6 'System.Web.UI.WebControls.MenuItem' does not contain a definition for 'item' C:\Inetpub\wwwroot\CssAdaptersTutorial1\App_Code\Adapters\MenuAdapter.cs 176 67 C:\...\CssAdaptersTutorial1\
I placed your code into the file C:\Inetpub\wwwroot\CssAdaptersTutorial1\App_Code\Adapters\MenuAdapter.cs
placing the writer.WriteAttribute("id", item.PROPERTY) in the BuildItem method
This is my OnInit method in the same physical file:
protected override void OnInit(EventArgs e) { base.OnInit(e); if (Extender.AdapterEnabled) { RegisterScripts(); menu.MenuItemDataBound += new MenuEventHandler(BindCustomAttributes); } }
Cheers, Dave
|