Error in removing Category Navigation WebPart from SharePoint Templates

Error in removing Category Navigation WebPart from SharePoint Templates

May 8th, 2006 // 5:05 pm @ Amar

In general, it is quite easy to remove the Category Navigation WebPart SPSWC:CategoryNavigationWebPart from the SharePoint template. Just open the proper file, locate


<SPSWC:CategoryNavigationWebPart runat=”server” id=”HorizontalNavBar” DisplayStyle=”HorizontalOneLayer” />


and delete it. ( The attributes may differ ).


On certain very stubborn pages, it is just not possible to remove it. For example, take the txtlstvw.aspx page. If you remove the category navigation webpart from this page, you are presented with the following error:


[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.SharePoint.Portal.WebControls.TextListingViewerPage.OnInit(EventArgs ea)
System.Web.UI.Control.InitRecursive(Control namingContainer) +240
System.Web.UI.Page.ProcessRequestMain() +195


I was very curious about it, as most of the pages do not complain so strongly if we remove the webpart from the template. There was no obvious link in the template HTML which proves that some other control uses it, and I removed almost all existing default controls from the page, but the error still persisted. This led me to believe that the error was somewhere in the code-behind for this page.


So I opened Reflector and loaded the Microsoft.SharePoint.Portal.dll and navigated to TextListingViewerPage->OnInit. There I found this piece of code :


this.HorizontalNavBar.CurrentCategoryID = this.BreadCrumbTrail.CurrentID = guid1.ToString();


There was no error checking code before this which tried to check if either HorizontalNavBar or BreadCrumbTrail objects were null. Thus we were stuck here. There is absolutely no way to remove these two webparts from this page without crashing it.


But… There was a sly approach. If I can’t remove them, then I can definitely hide them. My goal was to knock off these and add a custom branding with custom navigation controls. Hence, all I did was surround the Category Navigation Webpart and the Breadcrumb Trail Webpart with


<div style=”display:none;”>…</div>


Do this same trick if you ever have such a problem. I do remember having this problem while branding some other page in SharePoint but cannot remember which one. This is evidently sloppy coding on the part of the coder who wrote that page, and I hope problems like these would be corrected in the future releases.


Category : SharePoint

3 Comments → “Error in removing Category Navigation WebPart from SharePoint Templates”


  1. http://

    4 years ago

    Amar,

    Thanks so much for the post! I knew there had to be a work around.


  2. http://

    4 years ago

    Hi amar,
    this is great but i am facing issues in placing my custom webparts in onet.xml please let me know how it can be achieved.


  3. Amar Galla

    4 years ago

    If you see any existing onet.xml, in Modules -> File section you will see there is a section called AllUsersWebPart. You use that to wrap your custom webpart. Let me try to write up the entire process in a posting soon.


Leave a Reply

Latest Posts

Testimonials

"Amar clearly has a thorough knowledge of Sharepoint, this knowledge, coupled with his professionalism and dedication made him a tremendous asset to the project. He was the key contributor to the later stages of the project delivery effort (the really difficult bit, long hours and hard work that puts huge demands on people), and I can state categorically that without his focussed dedication and hard work we would not have been able to meet the timescales imposed upon the project."

Tim Ellis , Sharepoint Project Manager , Royal Bank of Scotland

Subscribe Now