Top Banner
SharePoint 2010 By: Usman Zafar Malik [MCTS: MOSS 2007], [MSCBSS: CRM 3.0 / 4.0], MCP Session - 5
35
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SharePoint 2010 Training Session 5

SharePoint 2010

By: Usman Zafar Malik

[MCTS: MOSS 2007], [MSCBSS: CRM 3.0 / 4.0], MCP

Session - 5

Page 2: SharePoint 2010 Training Session 5

SharePoint 2010 Development

Page 3: SharePoint 2010 Training Session 5

SharePoint 2010 Development• Simple Web parts• Advance Level Web parts

Page 4: SharePoint 2010 Training Session 5

SharePoint 2010 Simple Web parts

Page 5: SharePoint 2010 Training Session 5

Simple Web partsWhat are web parts?• Web Part is also called a Web Widget, is an ASP.NET

server control which is added to a Web Part Zone on Web Part Pages by users at run time. It enable end users to modify the content, appearance, and behavior of Web pages directly from a browser.

Possible scopes• Site Level.

Page 6: SharePoint 2010 Training Session 5

Simple Web partsTwo types of web parts

• Pure ASP.Net based web parts Derived from:- System.Web.UI.WebControls.WebParts.WebPart

– Generic web parts, that can be used in SharePoint and outside the SharePoint domain.

• SharePoint based web parts Derived from:- Microsoft.SharePoint.WebPartPages.WebPart

– Only used in the SharePoint domain.

Page 7: SharePoint 2010 Training Session 5

Simple Web partsFurther Categorization in Web parts

• Web parts - A class derived from “Webparts” class

• Visual web parts - A class derived from “Webparts” but also contains a user control in this web part. - Can’t be used in sandboxed solutions.

Page 8: SharePoint 2010 Training Session 5

Simple Web parts

Page 9: SharePoint 2010 Training Session 5

Simple Web parts

Page 10: SharePoint 2010 Training Session 5

Simple Web parts

Page 11: SharePoint 2010 Training Session 5

Simple Web parts

Page 12: SharePoint 2010 Training Session 5

Simple Web parts

Define properties in web parts

The WebBrowseable attribute specifies that the decorated property should appear in the editor component of the web part. It only allows the end user to modify the property and does nothing about persistence.

The Personalizable attribute specifies that the value of the decorated property must be persisted in the SharePoint backend, either in the user store (by default) or in the shared store (if the Shared scope is specified). It only cares about persistence and does nothing about the property presence in the editor component.

So, if you decorate a property with [WebBrowsable] and not [Personalizable], the end user will be able to modify it in the editor component but its new value won't be persisted.

Conversely, if you decorate a property with [Personalizable] and not [WebBrowsable], its value will be persisted but the end user won't be allowed to modify it.

Page 13: SharePoint 2010 Training Session 5

Simple Web parts Life Cycle

OnInit

OnLoad

CreateChildControls

OnPreRender

SaveViewState

Site Render

RenderContents

OnUnload

Dispose

Page 14: SharePoint 2010 Training Session 5

Visual Web parts

Page 15: SharePoint 2010 Training Session 5

Visual Web parts

Page 16: SharePoint 2010 Training Session 5

Visual Web parts

Page 17: SharePoint 2010 Training Session 5

Visual Web parts

Page 18: SharePoint 2010 Training Session 5

Visual Web parts Life Cycle SimpleVisualWebPart - OnInit

SimpleVisualWebPart - OnLoad

SimpleVisualWebPart - CreateChildControls

SimpleVisualWebPartUserControl - OnInit

SimpleVisualWebPartUserControl - OnLoad

SimpleVisualWebPartUserControl - Page_Load

SimpleVisualWebPart - OnPreRender

SimpleVisualWebPartUserControl - OnPreRender

SimpleVisualWebPart - SaveViewState

SimpleVisualWebPartUserControl - SaveViewState

SimpleVisualWebPart - Render

SimpleVisualWebPartUserControl - Render

Page 19: SharePoint 2010 Training Session 5

Visual Web parts Life CycleSimpleVisualWebPart - RenderContents

SimpleVisualWebPartUserControl - OnUnload

SimpleVisualWebPartUserControl - Dispose

SimpleVisualWebPart - OnUnload

SimpleVisualWebPart - Dispose

Page 20: SharePoint 2010 Training Session 5

SharePoint 2010 Advance Level Web parts

Page 21: SharePoint 2010 Training Session 5

Advance Level Web partsAdvance Level web parts?• Web part which contains toolpart, or we add

some custom controls in Web part Editor Tool part section.

Page 22: SharePoint 2010 Training Session 5

Advance Level Web partsAdvance Level web parts?• Web part which contains Custom Webpart Editor Section

• Two ways to create Custom Editor Part / Toolpart of Web part– By inheriting class from

“Microsoft.SharePoint.WebPartPages.ToolPart”

– By Implementing Interface “IWebEditable” on Toolpart class

Page 23: SharePoint 2010 Training Session 5

Advance Level Web partsUsing Toolpart class

Page 24: SharePoint 2010 Training Session 5

Advance Level Web partsUsing Toolpart class

Page 25: SharePoint 2010 Training Session 5

Advance Level Web parts using Toolpart class

Page 26: SharePoint 2010 Training Session 5

Advance Level Web parts using Toolpart class

Three Level of ToolParts–WebPartToolPart– CustomPropertyToolPart– Add Custom ToolPart

Page 27: SharePoint 2010 Training Session 5

Advance Level Web parts using Toolpart classWebPartToolPart

Default WebPart properties:-

• Appearance– Title– Width– Frame State– Frame Style

• Layout – Visible on Page – Direction– Zone– Part Order

• Advanced – Allow Minimize – Allow Close – Allow Zone Change– Allow Export Sensitive Properties – Detail Link – Description – Help Link – Icon File (Large) – Icon File (Small) – Missing Assembly Error – Target Audiences

Page 28: SharePoint 2010 Training Session 5

Advance Level Web parts using Toolpart class

CustomPropertyToolPart

An additional ToolPart that is added when custom properties are added to the WebPart programmatically.

Example:- First Name, Last Name

Page 29: SharePoint 2010 Training Session 5

Advance Level Web parts using Toolpart class

CustomToolPart

A toolpart which you have programmatically created and want to add in web part editor part.

Example:- Derived Classes from “Microsoft.SharePoint.WebPartPages.ToolPart” wants to add in the Web part’s Editor section.

Page 30: SharePoint 2010 Training Session 5

Advance Level Web parts using Toolpart class

public override Microsoft.SharePoint.WebPartPages.ToolPart[] GetToolParts(){ PersonDetailsToolPart CustomToolPart_ = new PersonDetailsToolPart(); CustomToolPart_.Title = "Company Details";

Microsoft.SharePoint.WebPartPages.ToolPart[] toolParts = new Microsoft.SharePoint.WebPartPages.ToolPart[3]; toolParts[0] = new Microsoft.SharePoint.WebPartPages.WebPartToolPart(); toolParts[1] = new Microsoft.SharePoint.WebPartPages.CustomPropertyToolPart(); toolParts[2] = CustomToolPart_;

return toolParts;}

Override the “GetToolParts()” method in order to add the custom toolpart in to your web part editor part section.

Page 31: SharePoint 2010 Training Session 5

Advance Level Web parts using Toolpart class

Common Webpart Propertiesthis.AllowMinimize = true/falsethis.AllowHide = true/false;this.AllowClose = false;this.ChromeType = PartChromeType.None; (if user wants to remove the border of the web part )

Page 32: SharePoint 2010 Training Session 5

Advance Level Web parts using IWebEditable Interface

Steps

- The web part which has the Custom Editor Part must implement the “IWebEditable “interface.

#region IWebEditable Members

EditorPartCollection IWebEditable.CreateEditorParts(){ // Adding your custom web part editor part (Example:- CustomEditor) List<EditorPart> editors = new List<EditorPart>(); editors.Add(new CustomEditor()); return new EditorPartCollection(editors);}

object IWebEditable.WebBrowsableObject{ get { return this; } // what is being edited :- Returning the Web part itself.} #endregion

Page 33: SharePoint 2010 Training Session 5

Advance Level Web parts using IWebEditable Interface

Steps- The Custom Editor Webpart must be inherited

from “EditorPart” class.- It must overrides two methods. 1- ApplyChanges Used for copy content from Editor Part to Web part. 2- SyncChanges Used for Copy content from Web part to Editor Part.

Page 34: SharePoint 2010 Training Session 5

Q & A

Page 35: SharePoint 2010 Training Session 5

Thanks !