CodeVerge.Net Beta
Login Idy
Register Password
  Forgot?
Explore    Item Entry    Members   
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > microsoft_downloads.css_friendly_control_adapters Tags:
Item Type: NewsGroup Date Entered: 3/1/2007 10:55:37 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 1 Views: 36 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
2 Items, 1 Pages 1 |< << Go >> >|
tobias123
Asp.Net User
How to create an adapter for the SiteMapPath control? How to handle the various templates (RootNodeTemplate, CurrentNodeTemplate, NodeTemplate...)?3/1/2007 10:55:37 AM

0/0

hi,

i want to create an adapter for the SiteMapPath control myself. The SiteMapPath is using various templates like the RootNodeTemplate, CurrentNodeTemplate, NodeTemplate and so on as you propably know. How to handle these in my overwritten RenderContents method? I really want to understand how is it working - not only accepting that it will work.

(If you want post your SiteMapPath adapter here but please explain it to me :) ) 

I also haven't understand the InstantiateIn method - (this ITemplate thing). How is it exactly working? The msdn isn't really a help here imho. I suppose it is using a NamingContainer.... but i still dont understand. Can you shed some light on this?

many thanks,tob
 

mandeep_bhangu
Asp.Net User
Re: How to create an adapter for the SiteMapPath control? How to handle the various templates (RootNodeTemplate, CurrentNodeTemplate, NodeTemplate...)?4/26/2007 11:11:18 AM

0/0

using System;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace CSSFriendly

{

public class SiteMapPathAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter 

{

public SiteMapPathAdapter()

{

//

}

protected override void OnInit(EventArgs e)

{

base.OnInit(e);

RegisterScripts();

}

private void RegisterScripts()

{


Page.ClientScript.RegisterClientScriptInclude(GetType(), GetType().ToString(), Page.ResolveUrl("~/JavaScript/MenuAdapter.js"));

}

protected override void RenderBeginTag(HtmlTextWriter writer)

{

if ((Control != null) && (Control.Attributes["CssSelectorClass"] != null) && (Control.Attributes["CssSelectorClass"].Length > 0))

{

writer.WriteLine();

writer.WriteBeginTag("div");

writer.WriteAttribute("class", Control.Attributes["CssSelectorClass"]);

writer.Write(HtmlTextWriter.TagRightChar);

writer.Indent++;

}

writer.WriteLine();

writer.WriteBeginTag("div");

writer.WriteAttribute("class", "AspNet-siteMap");

writer.Write(HtmlTextWriter.TagRightChar);

}

protected override void RenderEndTag(HtmlTextWriter writer)

{

writer.WriteEndTag("div");

if ((Control != null) && (Control.Attributes["CssSelectorClass"] != null) && (Control.Attributes["CssSelectorClass"].Length > 0))

{

writer.Indent--;

writer.WriteLine();

writer.WriteEndTag("div");

}

writer.WriteLine();

}

protected override void RenderContents(HtmlTextWriter writer)

{

writer.Indent++;

SiteMapPath item = (SiteMapPath)Control;


SiteMapProvider Provider = ((System.Web.UI.WebControls.SiteMapPath)(Control)).Provider;


SiteMapNodeCollection collection = new SiteMapNodeCollection();


SiteMapNode node = Provider.CurrentNode;


if (node != null)

{

collection.Add(node);

while (node != Provider.CurrentNode.RootNode)

{

node = node.ParentNode;

collection.Add(node);

}

}

BuildItems(collection, true, writer);


writer.Indent--;

writer.WriteLine();

}


private void BuildItems(SiteMapNodeCollection items, bool isRoot, HtmlTextWriter writer)

{

if (items.Count > 0)

{

writer.WriteLine();

writer.WriteBeginTag("p");

writer.Write(HtmlTextWriter.TagRightChar);

writer.Indent++;

for (int i = items.Count - 1; i > -1; i--)

{

// Write href links for item, if item is not currentNode

if (i != 0)

{

BuildItem(items[i], writer);

}

else

{

// if node is currentNode just print the title

writer.WriteLine();

writer.Indent++;

writer.Write(items[i].Title);

writer.Indent--;

}


}

writer.Indent--;

writer.WriteLine();

writer.WriteEndTag("p");

}

}

private void BuildItem(SiteMapNode item, HtmlTextWriter writer)

{

if ((item != null) && (writer != null))

{

if (item.Url.Length > 0)

{

writer.WriteLine();

writer.WriteBeginTag("a");

writer.WriteAttribute("href", Page.ResolveUrl(item.Url));

writer.WriteAttribute("class", "AspNet-SiteMap-Link");

writer.Write(HtmlTextWriter.TagRightChar);

writer.Indent++;

writer.WriteLine();

writer.Write(item.Title);

writer.Indent--;

writer.WriteLine();

writer.WriteEndTag("a");

writer.WriteLine();

writer.WriteBeginTag("span");

writer.WriteAttribute("class", "Hide");

writer.Write(HtmlTextWriter.TagRightChar);

writer.Indent++;

writer.Write(",");

writer.Indent--;

writer.WriteLine();

writer.WriteEndTag("span");

}


}

}

}

}
 
2 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:



 
All Times Are GMT