Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6935081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:03:20+00:00 2026-05-27T12:03:20+00:00

I created a web part the customized the quick lunch that can be expand

  • 0

I created a web part the customized the quick lunch that can be expand and collaps (+ and -) in sharePoint 2010, the problem is that when the site is loaded the default for quick lunch is expanded and i want it to be collapsed and i dont know how to do it
could you please help me.

the first code is for c# code for the user control

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;

namespace QuickLaunchWebpart.Quicklaunch_Webpart
{
public partial class Quicklaunch_WebpartUserControl : UserControl
{
    private void LoadQuickLauchDesign()
    {
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                Guid SiteID = SPContext.Current.Site.ID;
                Guid WebID = SPContext.Current.Web.ID;

                using (SPSite site = new SPSite(SiteID))
                {
                    using (SPWeb web = site.OpenWeb(WebID))
                    {
                        SPUser oUser = SPContext.Current.Web.CurrentUser;
                        SPNavigationNodeCollection nodecoll = web.Navigation.QuickLaunch;
                        foreach (SPNavigationNode node in nodecoll)
                        {
                            TableRow tr = new TableRow();
                            TableCell cell = new TableCell();
                            cell.Style.Add("padding-bottom", "15px");

                            Table innerTable = new Table();
                            innerTable.CellPadding = 0;
                            innerTable.CellSpacing = 0;
                            //  innerTable.BorderWidth = 1;
                            innerTable.Style.Add("width", "100%");
                            TableRow innerTrTitle = new TableRow();
                            innerTrTitle.Attributes.Add("onclick", "category_click()");
                            TableCell innerCellTitle = new TableCell();
                            innerCellTitle.CssClass = "category";

                            Image img = new Image();
                            img.ImageAlign = ImageAlign.Left;
                            img.ImageUrl = "/_layouts/images/MDNExpanded.png";
                            Label title = new Label();
                            title.Style.Add("font-size", "larger");
                            title.Text = node.Title;


                            Table titleCellTable = new Table();
                            titleCellTable.CellPadding = 0;
                            titleCellTable.CellSpacing = 0;
                            //titleCellTable.Attributes.Add("border", "1"); 
                            TableRow trtitleCellTable = new TableRow();
                            TableCell imageCell = new TableCell();
                            TableCell titleCell = new TableCell();
                            imageCell.Controls.Add(img);
                            titleCell.Controls.Add(title);
                            trtitleCellTable.Cells.Add(imageCell);
                            trtitleCellTable.Cells.Add(titleCell);
                            titleCellTable.Rows.Add(trtitleCellTable);


                            innerCellTitle.Controls.Add(titleCellTable);
                            innerTrTitle.Cells.Add(innerCellTitle);
                            innerTable.Rows.Add(innerTrTitle);

                            Panel div = new Panel();
                            div.Style.Add("background-color", "#FCFCFC");
                            //div.Style.Add("border-left", "1px solid #DBDDDE");
                            //div.Style.Add("border-bottom", "1px solid #DBDDDE");
                            Table childTable = new Table();
                            childTable.CellPadding = 0;
                            childTable.CellSpacing = 0;

                            childTable.Style.Add("width", "100%");

                            foreach (SPNavigationNode childnode in node.Children)
                            {
                                childTable.Rows.Add(ChildTableRow(childnode.Title, childnode.Url));
                            }
                            div.Controls.Add(childTable);

                            TableRow innerTrLinks = new TableRow();
                            innerTrLinks.Visible = true;
                            TableCell innerCellLinks = new TableCell();
                            innerCellLinks.Style.Add("border-right", "1px solid #DBDDDE");
                            innerCellLinks.Style.Add("padding-left", "15px");

                            innerCellLinks.Controls.Add(div);
                            innerTrLinks.Cells.Add(innerCellLinks);
                            innerTable.Rows.Add(innerTrLinks);

                            cell.Controls.Add(innerTable);
                            tr.Cells.Add(cell);
                            tbl1.Rows.Add(tr);
                        }
                    }
                }
            });
        }
        catch (Exception ex)
        {
            lblError.Text = ex.StackTrace;
            lblError.Visible = true;
        }
    }

    private TableRow ChildTableRow(string title, string Url)
    {
        TableRow tr = new TableRow();
        tr.Height = 20;
        TableCell cell = new TableCell();
        HyperLink link = new HyperLink();
        link.Text = title;
        link.NavigateUrl = Url;
        link.Attributes.Add("quick_link", "true");
        link.Style.Add("display", "block");
        cell.Controls.Add(link);
        tr.Cells.Add(cell);

        if (Request.Url.ToString().Contains(Url) && !(Request.Url.ToString().Contains("/SitePages/Home.aspx")))
        {
            tr.Attributes.Add("current", "true");
            link.Attributes.Add("current", "true");
        }

        return tr;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadQuickLauchDesign();

    }
}
}

the following code is for the java scripts used in usercontrol

<script type="text/javascript">

function category_click() {

    var evtSource = event.srcElement + '';
    var innerTblRef = null;

    if (evtSource == '[object HTMLTableCellElement]') {
        innerTblRef = event.srcElement.parentElement.parentElement;
    } else if (evtSource == '[object HTMLSpanElement]' || evtSource == '[object HTMLImageElement]') {
        innerTblRef = event.srcElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
    }

    //Locating the Collapse Image icon
    var imgRef = innerTblRef.rows[0].cells[0].firstChild.rows[0].cells[0].firstChild

    if (innerTblRef.rows[1].style.visibility == 'visible' || innerTblRef.rows[1].style.visibility == '') {
        innerTblRef.rows[1].style.visibility = 'hidden';
        innerTblRef.rows[1].style.display = 'none';
        imgRef.src = "/_layouts/images/MDNCollapsed.png";
    } else {
        innerTblRef.rows[1].style.visibility = 'visible';
        innerTblRef.rows[1].style.display = 'block';
        imgRef.src = "/_layouts/images/MDNExpanded.png";
    }
}

function link_hover() {
    var cellRef = event.srcElement;
    cellRef.className = "link_hover";

    if (cellRef + '' == '[object HTMLTableCellElement]') {      //Cell hover
        cellRef.firstChild.className = "link_hover";

    } else {        // Image hover
        cellRef.parentElement.className = "link_hover";
    }
}

function link_hout() {
    var cellRef = event.srcElement;
    cellRef.className = "link_hout";

    if (cellRef + '' == '[object HTMLTableCellElement]') {      //Cell hover
        cellRef.firstChild.className = "link_hout";

    } else {        // Image hover
        cellRef.parentElement.className = "link_hout";
    }
}

</script>

could you please help me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:03:21+00:00Added an answer on May 27, 2026 at 12:03 pm

    I solved my problem with a help from a friend by adding the following line in LoadQuickLauchDesign

    if(node.Children.Count>0) img.ImageUrl="/_layouts/images/MDNCollapsed.png"
    else img.ImageUrl = "/_layouts/images/MDNExpanded.png";
    

    instead of

    img.ImageUrl = "/_layouts/images/MDNExpanded.png";
    

    and in ChildTableRow function add the following
    innerTrLinks.Style.Add(“display”, “none”);
    innerTrLinks.Style.Add(“visibility”, “hidden”);
    instead of
    innerTrLinks.Visible = true;
    and it will work perfectly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a SharePoint web part which has custom properties that the user
I created a new Visual Web Part in VS 2010 (using Sharepoint Server 2010),
I have created a .net web part and deployed it on the sharepoint site.
I've created a custom ItemStyle_ContactDetails.xsl for a SharePoint 2010 content query web part, which
I am working on sharepoint 2010. I have created a simple visual web part
I've created a custom Web Part for SharePoint that interacts with SQL. Everything worked
So I am trying to create a web part in SharePoint 2010 that displays
I have created a SharePoint web part and inside this web part I am
I'm trying to create a SharePoint web part that will display all the users
I've created a link in Sharepoint using the Content Editor Web Part. My link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.