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: 4/26/2007 11:18:24 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 0 Views: 5 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
1 Items, 1 Pages 1 |< << Go >> >|
mandeep_bhangu
Asp.Net User
Learn How to create an adapter for the SiteMapPath control? How to handle the various templates (RootNodeTemplate, CurrentNodeTemplate, NodeTemplate...)?4/26/2007 11:18:24 AM

0/0

I needed a CSS Friendly Adapter for siteMapPath, but couldn't find one on net, so i made one of my own. it works bullocks.
 This will Print a CSS Friendly SiteMapPath, you can play around with it to print the kind of tags you need.
for now it just prints a <p> tag at the start and end , and then print <a> links separated by a comma (for accessibility point of view) ,
comma has span around it of class Hide, so you can hide it using simple css.
Give me a shout if you find any difficulties
 
cheers
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");
                }
                
            }
        }
    }
}
 
1 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

Re: I want to buy Flex for Linux - macromedia.labs.flexbuilder_linux - Web Programming Newsgroups ... control. learn how to create an adapter for the sitemappath ... how to handle the various templates (rootnodetemplate, currentnodetemplate, nodetemplate...
How to create an adapter for the SiteMapPath control? How to handle the ... How to handle the various templates (RootNodeTemplate, CurrentNodeTemplate, NodeTemplate... Re: How to create an adapter for the SiteMapPath control? ...
Re: I want to buy Flex for Linux - macromedia.labs.flexbuilder_linux - Web Programming Newsgroups ... control. learn how to create an adapter for the sitemappath ... how to handle the various templates (rootnodetemplate, currentnodetemplate, nodetemplate...
Single Sign on for multiple web applications... - newsgroup.asp-net ... learn how to create an adapter for the sitemappath control? how to handle the various templates (rootnodetemplate, currentnodetemplate, nodetemplate...


 
All Times Are GMT