Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » SharePoint » SharePoint Customization Tricks: Part II

SharePoint Customization Tricks: Part II

In this article, I'll show you another two tricks for customizing the list form toolbar.

Page Views : 8042
Downloads : 88
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
hideFormMenuItems.zip
 
 
DevExpress Free UI Controls
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction

This multipart series of articles is intended to help you getting ramped up with SharePoint Customization. It's about modifying the default SharePoint user experience, list forms customization, branding, skinning SharePoint portals, etc. In Part 1, I introduced a generic function that can be used to hide the list view toolbar menu items (e.g. New Item, Upload, Edit in Grid view, etc). If you haven't read it yet, I would encourage you do to that first. Today I'll show you another two tricks for customizing the list form toolbar.

Trick #2 : Hiding List Form Toolbar Menu Items!


Sometimes, you need to remove some items from the toolbar that appears at the top of DispForm.aspx.

Unfortunately, the "HideCustomAction" feature can merely hide the items which have been rendered through the "Custom Action" feature framework such as Site Actions and Site setting so let's take the same approach we took in Part 1 which is delving back into the world of JavaScript which I really find very handy when it comes to SharePoint customization.

The following function can be used to hide any toolbar item in dispform.aspx. Just call the function passing the names of the items comma separated (e.g. New Items, Alert Me, etc.). The function removes the items and of course the images rendered beside them (if found). Trick #3 will deal with where and how you can add the function to your list form.

Kindly note that the function is case sensitive so take care of the case the toolbar item names are rendered.

       hideFormMenuItems("New Item", "Alert Me");
        function hideFormMenuItems() {
            var titleToHide = "";
            var anchorTag;
            var allAnchorTags = document.getElementsByTagName('a');
            for (var i = 0; i < hideFormMenuItems.arguments.length; i++) {
                titleToHide = hideFormMenuItems.arguments[i];
                if (titleToHide != 'Alert Me') {
                    for (var j = 0; j < allAnchorTags.length; j++) {
                        anchorTag = allAnchorTags[j];
                        if (anchorTag.title.indexOf(titleToHide) != -1) {
                            anchorTag.parentNode.parentNode.parentNode.parentNode.
parentNode.style.display = "none";
                            anchorTag.parentNode.parentNode.parentNode.parentNode.
parentNode.nextSibling.style.display = "none";
                            break;
                        }
                    }
                }
                else {
                    for (var k = 0; k < allAnchorTags.length; k++) {
                        anchorTag = allAnchorTags[k];
                        if (anchorTag.id.indexOf("SubscribeButton") != -1) {
                            anchorTag.parentNode.parentNode.parentNode.parentNode.
parentNode.style.display = "none";
                            break;
                        }
                   }

                 }
            }
            var allSpanTags = document.getElementsByTagName("span");
            var spanTag;
            var toolbarRow;
            var lastCell;
            for (var m = 0; m < allSpanTags.length; m++) {
                spanTag = allSpanTags[m];

                if (spanTag.id == 'part1') {
                    toolbarRow = spanTag.childNodes[2].firstChild.firstChild;
                    lastCell = toolbarRow.lastChild.previousSibling
                    while (lastCell.style.display == 'none') {
                        lastCell = lastCell.previousSibling;
                    }
                    if (lastCell.innerText == '|') {
                        lastCell.style.display = 'none';
                    }
                    break;
                }
            }
        }

Trick #3 : Adding JavaScript through Content Editor Web Part!

The content editor web part gives you the ability to add any valid HTML on the web part page you place it and this surely includes <script> elements. The major advantage when using the content editor web parts that anyone with Designer permissions can do it quickly and easily.

Nice and Easy, let's do it, just go to Site Actions, Edit Page!!



Where the heck is Edit Page Menu Item?!!

Just like the old version, it's not available, I'm still not sure why they did that!

Trick #3 : Just append "&ToolPaneView=2" to the URL and you will have DispForm.aspx in the Edit Mode in your Browser.



Add a content editor web part just below the web part that renders the list form and insert the JavaScript of Trick #2 as shown in the figure below. (It's preferable to mark the content editor web part as hidden).





Exit the edit mode.


Tremendous, we managed to hide "New Item" and "Alert Me".

What about renaming "Edit Item" to "Edit Program" and Removing "Delete Item" but leaving the small image (x)? That is what I'm going to cover in trick#4 in the next part!

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Ayman ElHattab
Ayman M. El-Hattab works in ITWorx as a Software Engineer since October 2008, and since then has been working on building solutions using Microsoft Office, SharePoint 2007, .NET Framework 2.0/3.0/3.5, Microsoft SQL Server, C#, XML, Exchange, ASP.NET and others.

Ayman holds a Bachelor of Engineering degree in Mechatronics Engineering from Ain Shams University, and is a Microsoft Certified Application Developer, Solution Developer, SharePoint 2007 Specialist and Sun Certified Java Programmer.

Prior to ITWorx, Ayman worked for Asset Technology Group, NRG Solutions and he used to deliver courses for Mechatronics engineers (Robotics, Automatic Control, Artificial Intelligence, Image Processing and Data Acquisition courses). Ayman is a soccer fanatic and he supports Ahly FC and Barcelona FC.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Help by haric On March 18, 2009
Hey how do i hide toolbars items based on the user roles and permission. i am ablie to hide toolbar items but it hides for all users. i want to hide and show the toolbar items based on user roles and permisson . can you please help. Thanks
Reply | Email | Modify 
Re: Help by Bechir On March 18, 2009

To set security permissions based on roles you do as follow

/ /add the namespace

using System.Security.Principal;

//Create profile
GenericIdentity me = new GenericIdentity("Director");
String[] roles = {"Manager", "TheBoss"};
GenericPrincipal myPrincipal = new GenericPrincipal(me, roles);

//Tie the context to the current thread
Thread.CurrentPrincipal = myPrincipal;

if(myPrincipal.IsInrole("TheBoss"))
{
//Let him pass
}
else
{
// No way my freind
}

Reply | Email | Modify 
Re: Re: Help by haric On March 18, 2009

Hi

Thanks for the reply. Since i am new to the sharepoint , i don't know where and how  to add that code. i would really appreciate your help.

 

Thank

Hari

 

 

 

Reply | Email | Modify 
How about "Approve/reject Item" tab? by Scott On May 7, 2009
Great article!  Although, when I tried hiding the "Approve/reject Item" button it doesn't work.  Any chance that Javascript is getting caught up on the forward slash "/" ?

Any idea's how to hide the "Approve/reject Item" button?

Thanks!

--- UPDATE ---

I keep trying to figure this one out.  And after a little more perseverance, this is what I came up with.  I wanted to share this with everyone.

I replaced the following code: 

if (anchorTag.id.indexOf("SubscribeButton")!=-1)

with

if (anchorTag.id.indexOf("IOAppDenyItem")!=-1)
 
Thanks for getting me started!

Scott Rooke
Chicago, IL


<script type="text/javascript" language="javascript">

       hideFormMenuItems("Approve/reject Item");
        function hideFormMenuItems() {
            var titleToHide = "";
            var anchorTag;
            var allAnchorTags = document.getElementsByTagName('a');
            for (var i = 0; i < hideFormMenuItems.arguments.length; i++) {
                titleToHide = hideFormMenuItems.arguments[i];
               
                if (titleToHide != 'Approve/reject Item') {
                    for (var j = 0; j < allAnchorTags.length; j++) {
                        anchorTag = allAnchorTags[j];
                        if (anchorTag.title.indexOf(titleToHide) != -1) {
                            anchorTag.parentNode.parentNode.parentNode.parentNode.
parentNode.style.display = "none";
                            anchorTag.parentNode.parentNode.parentNode.parentNode.
parentNode.nextSibling.style.display = "none";
                            break;
                        }
                    }
                }
                else {
                    for (var k = 0; k < allAnchorTags.length; k++) {
                        anchorTag = allAnchorTags[k];
                        if (anchorTag.id.indexOf("IOAppDenyItem") != -1) {
                            anchorTag.parentNode.parentNode.parentNode.parentNode.
parentNode.style.display = "none";
                            anchorTag.parentNode.parentNode.parentNode.parentNode.
parentNode.nextSibling.style.display = "none";

                            break;
                        }
                   }

                 }
            }
            var allSpanTags = document.getElementsByTagName("span");
            var spanTag;
            var toolbarRow;
            var lastCell;
            for (var m = 0; m < allSpanTags.length; m++) {
                spanTag = allSpanTags[m];

                if (spanTag.id == 'part1') {
                    toolbarRow = spanTag.childNodes[2].firstChild.firstChild;
                    lastCell = toolbarRow.lastChild.previousSibling
                    while (lastCell.style.display == 'none') {
                        lastCell = lastCell.previousSibling;
                    }
                    if (lastCell.innerText == '|') {
                        lastCell.style.display = 'none';
                    }
                    break;
                }
            }
        }


        </script>
Reply | Email | Modify 
New to Sharepoint by Urvi On May 7, 2009
Hi I am totally new to sharepoint developer 2007. I never touch with software before. Please help me out how to execute the code and see the result with the webdesigning.. it would be great if anyone can help me out. Thank you in advance.
Reply | Email | Modify 
DevExpress Free UI Controls
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.