Thanks for your detailed explanation.
So I've basically get your page and code logic on the multi-language menus
and provider system... Though I haven't a concrete page and provider
class to test, what I'm thinking about is whether it'll be better not to
store control instances in Cache (sortedlist...). Generally dynamic
controls are recommended to created in page's life cycle , but not
precreated and cached.... So I think caching the SiteMapProvider instances
are reasonable, but for Menu and SitemapDataSource controls, I suggest you
create them in page everytime....
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: ASP.NET 2.0 menu renders invalid html/css
| thread-index: AcYQrh0pbsZfRPizTS6GE3mZTNd2aw==
| X-WBNR-Posting-Host: 84.162.122.129
| From: "=?Utf-8?B?ZHBvbXQ=?=" <>
| References: <E98E1CE2-5109-40AE-BCAE->
<>
| Subject: RE: ASP.NET 2.0 menu renders invalid html/css
| Date: Tue, 3 Jan 2006 13:39:02 -0800
| Lines: 129
| Message-ID: <78E869C2-BDF9-404B-BBD5->
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:368379
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello Steven,
|
| thanks for your reply.
|
| > As you mentioned that you use serveral SiteMapDataSources for each
| > language's menu, how do you specify them each? ASP.NET 2.0's default
| > SiteMapProvider only allow single SiteMap file.....
|
| I have written a custom SiteMapProvider (deriving from SiteMapProvider).
| This custom SiteMapProvider retrieves its data from an access database. I
| create ten instances of it and pass a language identifier in the
constructor.
| The implemenation of GetChildNodes takes care about the language of the
| current instance.
|
|
| > Also, would you provide some further description on the detailed code
logic
| > that you create the menu/hashtable item and bind it to a certain Menu
on
| > the page?
|
| Ok, I will post you some code with explanation:
|
|
| class GlobalDataSiteStructure
| {
| public SortedDictionary<int, SitemapProviderDBEx>
| sortedDictLangIDToSiteMapProvider = new SortedDictionary<int,
| SitemapProviderDBEx>();
| public SortedDictionary<int, KeyValuePair<Menu, SiteMapDataSource>>
| sortedDictLangIDToMenuAndSitemapDataSrc = new SortedDictionary<int,
| KeyValuePair<Menu, SiteMapDataSource>>();
|
| bool m_bSitemapDataSrcBound = false;
|
| public GlobalDataSiteStructure()
| {
| Initialize();
| }
|
| protected void Initialize()
| {
|
| // loop filling sortedDictLangIDToSiteMapProvider
| foreach (row in rows)
| {
| ...
| sortedDictLangIDToSiteMapProvider.Add(row.Language ID, new
| SitemapProviderDBEx(row.LanguageID));
|
| SiteMapDataSource smdatasrc = new SiteMapDataSource();
|
| smdatasrc.ShowStartingNode = false;
| smdatasrc.ID = "smdatasrc";
| mdatasrc.Provider =
sortedDictLangIDToSiteMapProvider[row.LanguageID];
|
| Menu SiteMenu = new Menu();
| SiteMenu.CssClass = "SiteMenu";
| SiteMenu.ID = "SiteMenu" + row.LanguageID;
|
| SiteMenu.DataSource = smdatasrc;
| }
|
|
|
| }
|
| public void MenuDataBind()
| {
| if (m_bSitemapDataSrcBound)
| return;
|
| foreach (KeyValuePair<int, KeyValuePair<Menu, SiteMapDataSource>> kvp
in
| sortedDictLangIDToMenuAndSitemapDataSrc)
| {
| Menu SiteMenu = kvp.Value.Key;
| SiteMenu.DataBind();
| }
| m_bSitemapDataSrcBound = true;
|
|
| }
|
|
| In my page containing the menu, I create an instance of
| GlobalDataSiteStructure, call method MenuDataBind on it and put it in the
| cache. Subsequent calls retrieve the GlobalDataSiteStructure instance
from
| the cache.
|
|
| ...
| GlobalDataSiteStructure globalDataSiteStructure =
| SiteStructureTools.GetGlobalDataSiteStructureFromC ache();
| globalDataSiteStructure.MenuDataBind();
| Menu SiteMenu =
|
globalDataSiteStructure.sortedDictLangIDToMenuAndS itemapDataSrc[m_iLanguageI
D].Key;
| HForm.Controls.Add(SiteMenu);
| ...
|
|
| public static GlobalDataSiteStructure
GetGlobalDataSiteStructureFromCache()
| {
| HttpContext context = HttpContext.Current;
| GlobalDataSiteStructure globalDataSiteStructure =
| (GlobalDataSiteStructure)context.Cache.Get("global DataSiteStructure");
| if (globalDataSiteStructure == null)
| {
| globalDataSiteStructure = new GlobalDataSiteStructure();
|
| HttpContext.Current.Cache.Add("globalDataSiteStruc ture",
| globalDataSiteStructure, null, DateTime.MaxValue, new System.TimeSpan(12,
0,
| 0), CacheItemPriority.High, null);
| }
|
| return globalDataSiteStructure;
| }
|
|
| That's it!
|
|
| >If possible, a simplified reproduce page would be much more
| >helpful ...
|
| It's quite hard to extract a small sample. If you don't get along with
the
| provided code and explanations, I will try to make a sample project.
Please
| let me know.
|
|
| Best regards,
| Dieter
|