More Questions Webpart

What is RenderContents,RenderControl,Renderchildren,Createchildcontrol events of Webpart?

What the HTMLTextWriter does in above events?

How  to Set the Custom Category for webparts

What  is the role of  SPwebpartManger and webpartZone ?how it is differenct for sharepoint and asp.net webparts?

The SharePoint Foundation Web Part infrastructure is built on top of a control named SPWebPartManager, which is derived from the ASP.NET WebPartManager control. The SPWebPartManager control overrides the standard behavior of the WebPartManager control to persist Web Part data inside the SharePoint Foundation content database instead of in the ASP.NET services database. In most cases, you do not have to worry about dealing directly with the SPWebPartManager control because the one required instance is already defined in v4.master. When you create a site page that links to v4.master, the SPWebPartManager control is already there. If you create your own custom ASPX pages that do not reference v4.master, and you want to support adding Web Parts to Web Part zones, you must add an SPWebPartManager control to the page.


To create Web Part zones for a Web Parts page in SharePoint Foundation, you should use the WebPartZone control that is defined inside the Microsoft.SharePoint.WebPartPages namespace, instead of using the standard WebPartZone control from ASP.NET.

When you create a Web Parts page for a standard ASP.NET application, you must add logic that interacts with the WebPartManager control to manage the Web Part display mode. Generally, you must also explicitly add editor parts and catalog parts to the page together with the HTML layout to accommodate them. Fortunately, you do not have to perform these changes when you create site pages for a SharePoint Foundation site. Instead, you inherit from the WebPartPage class that is defined inside the Microsoft.SharePoint.WebPartPages namespace, and it does all the work behind the scenes for you.

Solution Gallery – The Solution Gallery is the recommend placed to deploy a Web Part by using a sandboxed solution. It provides monitoring and security for your Web Parts by default. For more information about sandboxed solutions, see Sandboxed Solutions in SharePoint 2010.

global assembly cache — A global location where signed assemblies can be deployed, especially code for workflows, events, and Feature receivers. The global assembly cache enables you to share assemblies across numerous applications. The global assembly cache is automatically installed with the .NET runtime. Components are typically stored in C:\Windows\Assembly.

bin directory — A folder stored in your web application root directory; deployment to the bin directory should be limited to controls and Web Parts . The location of this folder is determined when the website is created in Internet Information Services (IIS). In SharePoint Foundation, this can occur either through the Central Administration site, or by manually creating a new website in IIS manager.

Why its required to have strong key name for webparts?

Strong naming uses a private key to digitally sign an assembly. Strong naming also stamps the assembly with a public key to validate the signature. This technique guards against unauthorized versions of a Web Part. If the public key fails to validate the digital signature, SharePoint Foundation refuses to run the module.

When you deploy a Web Part to the bin, the recommend practice is to strong name the assembly. When deploying a Web Part to the global assembly cache, the assembly must have a strong name. An assembly without a strong name is not recommended in SharePoint Foundation.

Why its required to create the safe control entry?

fundamental assumption of the SharePoint Foundation technology is that untrusted users can upload and create ASPX pages within the system that is running SharePoint Foundation. To prevent untrusted users from arbitrarily adding server-side code within ASPX pages, SharePoint Foundation provides a SafeControls list.

The SafeControls list is a list of approved controls and Web Parts specific to your SharePoint site that you have designated as safe for invocation on any ASPX page within your site. This list is contained in the web.config file in your web application root.

A SafeControl entry is an XML-based declaration of a Web Part that has the following form.


The SafeControl entry uses the assembly name, namespace, versioning information, and, if it is signed, it also requires a public key token to verify that the control is safe. If a Web Part assembly is signed, you can use the Strong Name Tool to retrieve the public key token for use in the SafeControl entry. The following command will retrieve the public key token for an assembly.

What is the Code access security?Why its required?

What are the different trust level ? what is its role?


SharePoint Foundation is a partial trust application by default. SharePoint Foundation can use the ASP.NET built-in trust levels but defines trust levels of its own:


WSS_Minimal trust level for the virtual server. This trust level grants all of the permissions in the ASP.NET Minimal trust as well as Web Part connections. The WSS_Minimal policy restricts the Web Part from accessing many resources for advanced operations, including the object model and file operations.
The WSS_Medium trust level grants greater access to the environment. Also, WSS_Medium allows access to the SharePoint Foundation object model and file operations including read, write, append, and path discovery. This trust level also allows access to environment variables

What is connnectable Webparts?


1.Creating an interface to define the string that is being provided.

Create the interface which implements this property in provider webpart

for example


public string TextBoxString




return _textBoxString;




_textBoxString = value;



Implement the method which returns the Interface type in Provider webpart

[ConnectionProvider("Provider for String From TextBox", "TextBoxStringProvider")]

public ITextBoxString TextBoxStringProvider()


return this;


2.Creating a Web Part by using the Microsoft Visual StudioWeb Part item template.
3.Creating a provider Web Part that defines a string.
4.Creating a consumer Web Part that uses and displays the string.
In consumer Webpart,Override the Prerender event

protected override void OnPreRender(EventArgs e)



if (_myProvider != null)


myLabel.Text = _myProvider.TextBoxString;



Implement the method in consumer webpart as follows

[ConnectionConsumer("String Consumer", "StringConsumer")]

public void TextBoxStringConsumer(ITextBoxString Provider)


_myProvider = Provider;


5.Creating a Web Parts page and connecting the provider and consumer Web Parts.
example: http://msdn.microsoft.com/en-us/library/ff597538.aspx