Article prepared by Srinath Sadda© meraTechExplorer | Resources for Technical Professionals
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.configfile. Entries made in the safe controls element of SharePoint are encountered by the SharePointHandler object and will beloaded 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 optionalelements.
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 beoutput for rendering. Basically, it will add any child ASP.NET controls that are called instantiating each control with its relevantproperties set, wire any relevant event handlers to the control, etc. Then the add method of the control class will add thecontrol to the controls collection. In the relevant WebPart render method, the EnsureChildControls method can be called (orset to false if no child controls should be called) to ensure that the CreateChildControls method is run. When usingCreateChildControls 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, setthe 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 willoutput to an HTML stream. RenderContents is used to tell how the controls that are going to be displayed in the WebPartshould be rendered on the page.
I got asked what the difference between CreateChildControls and the RenderContents method. TheCreateChildControls method is used to add controls to the WebPart, and the RenderContents method is used to tellthe page framework how to render the control into HTML to display on a 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 responsiblefor 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.”
I got asked how many WebPartManager controls should be on a page. In order to have WebParts ona page there has to be just one WebPartManager control to manage all the WebParts on the page.
What is a SPSite and SPWeb object, and what is the difference between each of the objects?
The SPSite object represents a collection of sites (site collection [a top level site and all its subsites]). The SPWeb objectrepresents an instance SharePoint Web, and SPWeb object contains things like the actual content. A SPSite object containsthe various subsites and the information regarding them.
How would you go about getting a reference to a site?
oSPSite = new SPSite("http:/server");
oSPWeb = oSPSite.OpenWeb();