Solved

//NOTE: The following placeholder declaration is required by the Web Form Designer.

Posted on 2009-07-11
1
282 Views
Last Modified: 2012-05-07
Why do I need this in my code?
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Globalization;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.ComponentModel;
 
namespace OmegaLove.Web.UI
{
   
    public partial class ctrlBreadCrumb : OmegaLoveBasePageUserControl
    {
        public struct PageCrumb
        {
            private short _level;
            private string _url;
            private string _linkName;
 
            public PageCrumb(short level, string url, string linkName)
            {
                _level = level;
                _url = url;
                _linkName = linkName;
            }
 
            public short Level
            {
                get { return _level; }
            }
 
            public string Url
            {
                get { return _url; }
            }
 
            public string LinkName
            {
                get { return _linkName; }
            }
        }
 
 
        protected System.Web.UI.WebControls.Label lblTrail;
        //NOTE: The following placeholder declaration is required by the Web Form Designer.
        //Do not delete or move it.
        private System.Object designerPlaceholderDeclaration;
 
        //Variable holding the Link name of the page
        private string _tailName;
 
        //Variable holding the level of the page
        private short _level;
 
        //The pagecrumb object of the current page
        private PageCrumb _pageCrumb = new PageCrumb();
 
        //We will use a sorted list as we can use the level as key 
        private SortedList _crumbList;
 
 
        //Each page has a level. The page should declare its level
        public short Level {
           // TO DO : We can check for some constraints here
           get { return _level; }
           set { _level = value; }
        }
 
        //Each page needs a meaningful name of it. Let them declare it
        public string TailName {
           // TO DO : We can check for some constraints here
           get { return _tailName; }
           set { _tailName = value; }
        }
 
        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
        }
 
        /// <summary>
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }
 
        #endregion
 
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(Page.IsPostBack))
            {
 
                //Minimum level is 1
                if ((_level <= 0))
                {
                    _level = 1;
                }
 
                //If no friendly name gives Untitled as default
                if ((string.IsNullOrEmpty(_tailName)))
                {
                    _tailName = "Untitled";
                }
 
                //Create a Crumb object based on the properties of this page
                _pageCrumb = new PageCrumb(_level, Request.RawUrl, _tailName);
 
                //Check our Crumb is there in the session...if not create and add it...else get it 
                if (Session["HASH_OF_CRUMPS"] == null)
                {
                    _crumbList = new SortedList();
                    Session.Add("HASH_OF_CRUMPS", _crumbList);
                }
                else
                {
                    _crumbList = (SortedList) Session["HASH_OF_CRUMPS"];
                }
 
                //Now modify the List of the breadcrumb
                ModifyList();
                // Put the breadcrumb from the session of sortlist
                PutBreadCrumbs();
 
 
            }
 
        }
 
        private void ModifyList()
        {
            //Remove all Entries from the list which is higher or equal in level
            //Because at a level there can be max 1 entry in the list
            RemoveLowerLevelCrumbs();
            //If level is 1 set the Crumb as home
            if (_pageCrumb.Level == 1)
            {
                _crumbList.Clear();
 
                _crumbList.Add((short)1, new PageCrumb(1, "/Home.aspx", "Home"));
            }
            else
            {
                //If nothing in the list adds the home link first
                if (_crumbList.Count == 0)
                {
                    _crumbList.Add((short)1, new PageCrumb(1, "/Home.aspx", "Home"));
                }
                //Now add the present list also no other check is required here as we have cleaned up the 
                //List at the start of the function
                _crumbList.Add(_level, _pageCrumb);
            }
        }
 
        //Function will remove all the entries from the list which is higher or equal to the
        //present level
        private void RemoveLowerLevelCrumbs()
        {
 
            ArrayList removalList = new ArrayList(_crumbList.Count);
            foreach (short level in _crumbList.Keys)
            {
                if ((level >= _level))
                {
                    removalList.Add(level);
                }
            }
            //Now remove all keys in the list
            foreach (short level in removalList)
            {
                _crumbList.Remove(level);
            }
        }
 
 
 
        private void PutBreadCrumbs()
        {
            StringBuilder linkString = new StringBuilder();
 
            PageCrumb pageCrumb = new PageCrumb();
            int index = 0;
 
            for (index = 0; index <= _crumbList.Count - 2; index++)
            {
                pageCrumb = (PageCrumb)_crumbList.GetByIndex(index);
                linkString.Append(string.Format("<a href = {0} >{1} </a>", pageCrumb.Url, pageCrumb.LinkName));
                linkString.Append(" > ");
            }
            //Add the tail also
            pageCrumb = (PageCrumb)_crumbList.GetByIndex(index);
            linkString.Append(pageCrumb.LinkName);
 
 
            lblTrail.Text = linkString.ToString();
        }
    }
}

Open in new window

0
Comment
Question by:mathieu_cupryk
1 Comment
 
LVL 6

Accepted Solution

by:
microbolt earned 500 total points
ID: 24833250
That is an "partial" class.  Another part of the class may need to call upon it.  Removing it might cause an exception in your app.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Checkbox in a dynamic GridVIew is not clickable? 5 36
Problem to refer to value 8 62
Where did System.Data.Objects go? 2 40
asp.net mvc5 6 20
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question