Sharepoint Interview Questions Related to webparts

What is Webpart?

Webparts can be considered as reusable widgets (similar to the yahoo ones) which work independently (though they can communicate) and are individually configurable. This makes the task of showing up of different logical sections on the same web page easier; especially while doing independent development. Brought out initially with Sharepoint 2003, it was supported in ASP.NET extensively and now in MOSS 2007 .

Web Parts are componentized, self-contained packages of user interface that can be dropped into place on SharePoint Web Part pages to provide discrete sets of functionality to users.

How you debug custom webpart in MOSS?

At that point you must manually attach the debugger to the process running the code.  The process you will need to attach to is the w3wp.exe process. 
To do this:
1. Go to Debug -> Attach to Process.
2. Check the Show processes from all users and Show processes in all sessions checkbox.
3. Scroll down to the w3wp process and click Attach.


Which class you inherit for creating a webpart?

System.Web.UI.WebParts.WebPart
Here is the example:
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Demo.Webparts
{
public class demowebpart : System.Web.UI.WebControls.WebParts.WebPart
{

What are the main methods to be override  while creatng custom webpart?

CreateChildControls()
RenderControl(HtmlTextWriter writer)
The CreateChildren Control is same as in .Net 1.1, that it would create and add controls to this Web Part Class,. In this case I have only added a WebControl.Calender Object. The RenderControl Method is an override for the WebPart Base Class and calls the RenderChildren Method, this causes the Children Controls to be rendered on the Particular HtmlTextWriter passed as a parameter to the method.

What is the procedure for deploying custom webpart?

http://www.developer.com/net/asp/article.php/3620316


What is the GAC?

The GAC stands for the global assembly cache. It is the machine wide code cache which will give custom binaries place into the full trust code group for SharePoint. Certain SharePoint assets, such as Feature Receivers need full trust to run correctly, and therefore are put into the GAC. You should always try to avoid deployment to the GAC as much as possible since it will possibly allow development code to do more than it was intended to do. 
 
What is strong naming (signing) a WebPart assembly file mean? 

Signing an assembly with a strong name (a.k.a strong naming) uses a cryptographic key pair that gives a unique identity to a component that is being built. This identity can then be referred throughout the rest of the environment. In order to install assemblies into the GAC, they must be strongly named. After signing, the binary will have a public key token identifier which can be use to register the component in various other places on the server. 
 
What are safe controls, and what type of information, is placed in that element in a SharePoint web.config file?

When you deploy a WebPart to SharePoint, you must first make it as a safe control to use within SharePoint in the web.config file. Entries made in the safe controls element of SharePoint are encountered by the SharePointHandler object and will be loaded in the SharePoint environment properly, those not will not be loaded and will throw an error. In the generic safe control entry (this is general, there could be more), there is generally the Assembly name, the namespace, the public key token numeric, the typename, and the safe declaration (whether it is safe or not). There are other optional elements. 
 
What is the CreateChildControls() method? How can you use it to do something simple like displaying a Label control?

The CreateChildControls method in WebParts is used to notify the WebPart that there are children controls that should be output for rendering. Basically, it will add any child ASP.NET controls that are called instantiating each control with its relevant properties set, wire any relevant event handlers to the control, etc. Then the add method of the control class will add the control to the controls collection. In the relevant WebPart render method, the EnsureChildControls method can be called (or set to false if no child controls should be called) to ensure that the CreateChildControls method is run. When using CreateChildControls it implies that your WebPart contains a composition of child controls.

In order to create something like a label control in Create, you would create a new label control using the new keyword, set the various properties of the control like Visible=True and ForeColor = Color.Red, and then use Controls.Add(myLabelControl) to add the control to the controls collection. Then you can declare EnsureChildControls in the Render method of the WebPart. 
 
What does the RenderContents method do in an ASP.NET 2.0 WebPart? 

The render contents method will render the WebPart content to the writer, usually an HtmlTextWriter since WebParts will output to an HTML stream. RenderContents is used to tell how the controls that are going to be displayed in the WebPart should be rendered on the page. 
 
What is the WebPartManager sealed class? What is its purpose? 

The WebPartManager sealed class is responsible for managing everything occurring on a WebPart page, such as the WebParts (controls), events, and misc. functionality that will occur in WebPartZones. For example, the WebPartManager is responsible for the functionality that is provided when you are working with moving a WebPart from WebPartZone to WebPartZone. It is known as the "the central class of the Web Part Control Set."

While creating a Webpart, which is the ideal location to Initialize my new controls ?

Override the CreateChildControls method to include your new controls. To make sure that the new controls are initialized.. call 'EnsureChildControls' in the webparts Render method. You can control the exact Rendering of your controls by calling the .Render method in the webparts Render method.




Comments

Sharepoint essential materials.