protected void Page_Load(object sender, EventArgs e)
        {
            // SET THE DEFAULT PAGE SIZE AND ADD A NEW OPTION BASED ON MaxItems parameter value if needed
            if (!Page.IsPostBack)
            {
                CategoryBreadCrumbs1.Visible = this.DisplayBreadCrumbs;
            }

            InitializePageSize();

            if (IsValidCategory())
            {
                string eventTarget = Request["__EVENTTARGET"];
                if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions"))
                {
                    PageSizeOptions.ClearSelection();
                    ListItem item = PageSizeOptions.Items.FindByValue(_pageSize.ToString());
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }

                if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("SortResults"))
                {
                    string sortOption = Request.QueryString["s"];
                    if (!string.IsNullOrEmpty(sortOption))
                    {
                        SortResults.ClearSelection();
                        ListItem item = SortResults.Items.OfType <ListItem>().FirstOrDefault(x => string.Compare(x.Value, sortOption, StringComparison.InvariantCultureIgnoreCase) == 0);
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(eventTarget))
                {
                    if (eventTarget.EndsWith("PageSizeOptions") || eventTarget.EndsWith("SortResults"))
                    {
                        string url = Request.RawUrl;
                        if (url.Contains("?"))
                        {
                            url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
                        }
                        url += "?s=" + SortResults.SelectedValue;
                        url += "&ps=" + _pageSize.ToString();
                        Response.Redirect(url);
                    }
                }


                Caption.Text = this.DefaultCaption;

                if (_Category != null)
                {
                    // use category name if no default name is specified
                    if (string.IsNullOrEmpty(Caption.Text))
                    {
                        Caption.Text = _Category.Name;
                    }

                    CategoryBreadCrumbs1.CategoryId = this.CategoryId;

                    if (!string.IsNullOrEmpty(_Category.Summary) && ShowSummary)
                    {
                        CategorySummary.Text = _Category.Summary;
                    }

                    if (!string.IsNullOrEmpty(_Category.Description) && ShowDescription)
                    {
                        CategoryDescriptionPanel.Visible = true;
                        CategoryDescription.Text         = _Category.Description;
                    }
                    else
                    {
                        CategoryDescriptionPanel.Visible = false;
                    }
                }
                else
                {
                    // IT IS ROOT CATEGORY
                    CategoryBreadCrumbs1.CategoryId = this.CategoryId;
                    if (ShowSummary)
                    {
                        CategorySummary.Text = DefaultCategorySummary;
                    }
                }

                if (_Category != null)
                {
                    int count = WebpageDataSource.CountForCategory(_Category.Id, true, true);
                    if (count > 0)
                    {
                        _currentPageIndex = AlwaysConvert.ToInt(Request.QueryString["p"]);
                        if (_pageSize == 0)
                        {
                            _lastPageIndex = 0;
                        }
                        else
                        {
                            _lastPageIndex = ((int)Math.Ceiling(((double)count / (double)_pageSize))) - 1;
                        }

                        CatalogNodeList.DataSource = WebpageDataSource.LoadForCategory(_Category.Id, true, true, SortResults.SelectedValue, _pageSize, (_currentPageIndex * _pageSize));
                        CatalogNodeList.DataBind();
                        int startRowIndex = (_pageSize * _currentPageIndex);
                        int endRowIndex   = startRowIndex + _pageSize;
                        if (endRowIndex > count || endRowIndex == 0)
                        {
                            endRowIndex = count;
                        }
                        if (count == 0)
                        {
                            startRowIndex = -1;
                        }
                        ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, count);
                        ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, count);
                        BindPagingControls();
                    }
                    else
                    {
                        phEmptyCategory.Visible = true;
                    }

                    AbleCommerce.Code.PageVisitHelper.RegisterPageVisit(_Category.Id, CatalogNodeType.Category, _Category.Name);
                }
            }
        }