Override Chrome Type Webpart
Asked Answered
C

3

13

I made a Webpart in Sharepoint 2010, and I need that the property "Chrome Type" allways set a "None" value.

I was looking for ways to force the Combobox to "None", or overriding the "Chrome Type" in the C# class, but I didn't find any way to do them. What is the best way to set this property?

Override Chrometype

Callous answered 28/3, 2011 at 7:33 Comment(0)
C
7

You should be able to modify .ChromeType property of the web part in code.

Keep in mind where you do this in the web part life-cycle.

If you do it as part of the Render method it will be too late - the chrome has already been drawn by then.

On the other end of the scale if you do it to early then your setting will be overridden when SharePoint applies the settings from the toolpart.

Look at doing it in something like the OnPreRender event.

Chiro answered 28/3, 2011 at 9:57 Comment(0)
V
27

The other option is to use the .webpart file to specify this as the default using the ChromeType property. You can do this in your Visual Studio solution (as below) or you can edit the .webpart file directly in the Web Part Gallery.

As this is a no code approach, it seems a bit simpler than the C# route.

Try this:

<?xml version="1.0" encoding="utf-8"?>
<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="<<ClassName>>, $SharePoint.Project.AssemblyFullName$" />
  <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
</metaData>
<data>
  <properties>
    <property name="Title" type="string">Custom List Form</property>
    <property name="Description" type="string">Provides A Data Entry Form For a SharePoint List</property>
    <!-- SEE CHROME TYPE BELOW -->    
    <property name="ChromeType" type="chrometype">None</property>
  </properties>
</data>
</webPart>
</webParts>
Vervain answered 23/5, 2011 at 15:58 Comment(2)
I second the .webpart approach.Brainstorming
This should be the answer, because it is much more elegant and reusable then the code approach (however it only sets the default value for the ChromeType, but as far as I understand it should be enough for the case mentioned in the original question).Fungous
C
7

You should be able to modify .ChromeType property of the web part in code.

Keep in mind where you do this in the web part life-cycle.

If you do it as part of the Render method it will be too late - the chrome has already been drawn by then.

On the other end of the scale if you do it to early then your setting will be overridden when SharePoint applies the settings from the toolpart.

Look at doing it in something like the OnPreRender event.

Chiro answered 28/3, 2011 at 9:57 Comment(0)
F
4

This is another solution to change the ChromeType using PartChromeType="None"

<WebPartPages:WebPartZone runat="server" Title="Banner" ID="Banner" PartChromeType="None" />

The options supported are:

  • BorderOnly
  • Default
  • None
  • TitleAndBorder
  • TitleOnly

To update the changes is sometimes necessary to remove and reinsert the webpart

Fabiano answered 2/10, 2015 at 23:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.