Removing/Hiding the Web Part Title in SharePoint through Code

No.of Views2073
Bookmarked1 times
Downloads 
Votes0
By  Dhananjay Kumar   On  16 Feb 2010 00:02:56
Tag : SharePoint , Development and Programming
This article is on very simple topic. In this article; I am going to show how to hide Web Part’s title in SharePoint through code.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Objective

This article is on very simple topic. In this article; I am going to show how to hide Web Part’s title in SharePoint through code.

Note
Even this requirement of hiding WebPart title sounds relatively easier task but believe me I gave my 3 hours solving this.

Step 1 Create Web Part

1. Create new web part by clicking File->New->Project->SharePoint and then selecting Web Part Project template. I am giving name MyWebPart.

Image Loading

2. Write code for web part. For Demo purpose I am just adding a label to Web Part to display message.

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace MyWebPart
{
[Guid("7447c788-1380-40cc-8134-5e40555dd9b0")]
public class mywebpart : System.Web.UI.WebControls.WebParts.WebPart
{
public mywebpart()
{
}

protected override void CreateChildControls()
{
base.CreateChildControls();

// TODO: add custom rendering code here.Label label = new Label();
label.Text = " This is Web Part without Title";
this.Controls.Add(label);
}
}
}

Step 2: Hiding the Web Part title

Open MyWebPart.webpart file. Just see in solution explorer for this file. Modify this file as below. See the code highlighted in yellow. Just comment the default Title and Description properties. If you want you could not comment Description property. But to hide title; you have to comment title property. After commenting add two properties. One for ChromeState and other for ChromeType.

<?xml version="1.0" encoding="utf-8"?><webParts><webPart xmlns="http://schemas.microsoft.com/WebPart/v3"><metaData><!--
The following Guid is used as a reference to the web part class,
and it will be automatically replaced with actual type name at deployment time.
--><type name="7447c788-1380-40cc-8134-5e40555dd9b0" /><importErrorMessage>Cannot import WebPart1 Web Part.</importErrorMessage></metaData><data><properties><!--<property name="Title" type="string">WebPart1 Web Part</property><property name="Description" type="string">WebPart1 Description</property>--><property name="ChromeState" type="chromestate">Normal</property><property name="ChromeType" type="chrometype">None</property></properties></data></webPart></webParts>

Note:
For proper output make sure about upper and lower cases. Give properties in the same case as they listed above.

Step 3: Packaging and Deploying the WebPart

1. Right click to the Project. After this go to debug tab. There in URL give the Site URL; where you want to deploy the Web Part. For my case I am deploying it to the Web Application running on port 2222. So I just pasted that URL there.

Image Loading

2. Build the solution.
3. Right click on the solution and click on Package the solution.
4. Right click then click on Deploy Solution.
5. You should get a successful message in output window. To see output window click View -> Output from menu of Visual Studio.

Step 4: Testing the Web Part

1. Open the site collection where you deployed the web part.
2. Go to Site Setting then Site Collection feature. You should able to see WebPart1 is deployed as feature and it is active.

Image Loading

3. Go to Site Action then Edit Page then add a web part. Add the MyWebPart web part ;which we created in step 2.
4. Click on Home tab. You should able to see the Web Part without the title. See below in Red rectangle.

OutPut

Image Loading

Conclusion

I shown in this article how to hide title of a Web Part. Thanks for reading

 

 
Sign Up to vote for this article
 
About Author
 
Dhananjay Kumar
Occupation-Software Engineer
Company-Infosys Technolgies,Pune
Member Type-Gold
Location-India
Joined date-20 Jul 2009
Home Page-http://dhananjaykumar.net/
Blog Page-http://dhananjaykumar.net/
Dhananjay Kumar is Microsoft MVP on connected system. He blogs at http://dhananjaykumar.net/ . You can follow him http://twitter.com/debugmode_/ and reach him at dhananjay.25july@gmail.com
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top