Posts

Showing posts from June, 2009

WebPart Life Cycle

1. OnInit: event used to create controls of web part 2. OnLoad: 3. CreateChildControls: event used to set properties and default values to controls collection If the page is being rendered for the first time the method generally occurs after the OnLoad event. If it is Postback, It is called before OnLoad event. EnsureChildControls: It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it. 4. LoadViewState: The view state of the web part is populated over here. 5. OnPreRender: event used to set up business logic related work and in this routine controls value kept by viewstate 6. Render: event creates the HTML that appears in the body of the Web Part. 7. OnUnload: 8. Dispose:

Creating Views in SharePoint Using the object model

Using the object model we can create a SharePoint views programmatically. The query for the view uses an SPQuery which uses CAML. //Define an array to hold the columns required in the view String[] colArray = new String[] { "FName", "LName", "Email” }; //Add the array to a string collection StringCollection colCollection = new StringCollection(); colCollection.AddRange(colArray); //Define the query for the view String viewQry = “Your CAML Query Here’; HTML clipboard //Define the new view & Add to the List (100 is the item limit, true is allow paging and false is to set as the default view) SPView newView = YourList.Views.Add(“View Title”, colCollection, viewQry, 100, true, false);