Tuesday, September 28, 2010

Scoping Master Pages in SharePoint

Master pages provide the look and feel and standard behavior that you want for all of the pages in your site. Together with content pages, they produce output that combines the layout of the master page with content from the content page. 
Because Windows SharePoint Services is built on top of Microsoft ASP.NET 2.0, it supports master pages for defining elements that are common to all pages. You can specify all of the shared elements of your site in the master page or pages, and add content page-specific elements to content pages.

Master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. You can then create individual content pages that contain the content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.
Windows SharePoint Services pages that end users can customize—list view pages, list form pages, and Web Part Pages—are content pages that contain the content to display. When a user requests a content page, it is merged with a master page to produce output that combines the layout of the master page with the content from the content page.
All content pages share the same page structure—the global breadcrumb, site title area, top navigation, page title area, and left navigation bar. In Windows SharePoint Services, this shared page structure is moved into a master page called default.master, which is used by all content pages, including the following:
  1. default.aspx
  2. AllItems.aspx, DispForm.aspx, NewForm.aspx, and EditForm.aspx: for all lists 
  3. Upload.aspx and Webfldr.aspx: for all document libraries 
  4. Any new content pages that are created in this site
 
There are three levels to attach content pages to a master page:
  • At the page level: you can use a page directive in each content page to bind it to a master page, as in the following code example. 
  • At the application level: By making a setting in the pages element of the application's configuration file (Web.config), you can specify that all ASP.NET pages (.aspx files) in the application automatically bind to a master page. The element might look like the following. If you use this strategy, all ASP.NET pages in the application that have Content controls are merged with the specified master page. (If an ASP.NET page does not contain Content controls, the master page is not applied.)
  • At the folder level: This strategy is like binding at the application level, except that you make the setting in a Web.config file in one folder only. The master-page bindings then apply to the ASP.NET pages in that folder.

Monday, September 27, 2010

Important Considerations for SharePoint Master Pages

Consider the following when you are working with master pages in Windows SharePoint Services:

1. Compilation mode for master pages works like the compilation mode for any other .aspx page. You can change the compilation mode at any time, and you can combine compilation modes for master and content pages, for example, a compiled master page and a content page that is not compiled. Remember, however, that although compiled master pages can contain inline script, after that page is customized in Office SharePoint Designer, or a similar tool, the page is no longer compiled and script no longer runs. For that reason, it is recommended that you do not include inline script in your master pages.

2. By default, Windows SharePoint Services does not use nested master pages, but does not block users from using them. You can create master pages at any level, and have a master page that refers to another master page. For example, you can reference one master page from another master page using the following directive:

<%@ Master master=MyParent.master %>

Some page editors may not effectively support nested master pages.

3. You cannot add Web Parts in zones to a master page. You can add static Web Parts (parts outside of a zone) to a master page, but you cannot add dynamic Web Parts to master pages. You can add zones to master pages and later add Web Parts to the zone in the browser, but the Web Parts are associated with the content page.

Sunday, August 1, 2010

Few notes about Abstract class and Interfaces...

when you believe that derive class behavior & action would be similar to base in most of the case you use abstract; and when you think that behavior is same but action can change for different derived classes you use interface.

Abstract base class shows is-a relationship while interface shows "can do" relationship for ex: humans and fish can swim while human and horse can run and human, horse and fish are (is a) animals.

So abstract class Animal can be a base class inherited by all humans, horse and fish. While animal itself doesn't represent any physical entity so abstract. A behavior "breath" will be applied to all in animals if defined in animal abstract class itself. May be later on you may want to add "Eat" behavior in abstract class which would not create any consequences on derived class. Or you might support another version of animal which can represent the abstract properties of aliens too.

while Interface IRun will be inherited by human and horse only while ISwim can be inherited by human and Fish only and all these derived classes will define their own style of swimming and running while if you add another behavior in same interface you have to define it in all the derived class.

Sample implementation will be like

Class Human: Animals, IRun, ISwim{}

Class Horse: Animals, IRun{}

Class Fish: Animals,ISwim{}

Class Bird: Animals, IFly{}

later on updated versions of animal

Class Alien: Animals, IFly, ISwim, IRun, ISpace {} //though hypothetical considered just for example :)
REF: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/0ab0d038-61b6-43e0-82da-33338f52f3bf

Why abstract allows constructor? What is the use of it?

So that derived class can call it where creating it's object and abstract base class can initialize it's members.

"Because abstract classes should never be instantiated, it is important to correctly define their constructors. It is also important to ensure that the functionality of your abstract class is correct and easily extended. The following guidelines help ensure that your abstract classes are correctly designed and work as expected when implemented.

Do not define public or protected internal (Protected Friend in Visual Basic) constructors in abstract types &define a protected or an internal constructor in abstract classes:

Constructors with public or protected internal visibility are for types that can be instantiated. Abstract types can never be instantiated. If you define a protected constructor in an abstract class, the base class can perform initialization tasks when instances of a derived class are created. An internal constructor prevents the abstract class from being used as the base class of types that are not in the same assembly as the abstract class. "

http://msdn.microsoft.com/en-us/library/ms229047.aspx

REF: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/175aad18-4514-4320-8195-be480dee4627

Why use reference of abstract class to create object

It is more related to OOPS concept rather than how we do it C#. Liskov substitution principle explain the relation in the best way

"Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T". Here you can assume T as TextWriter and S as Stream Writer

http://en.wikipedia.org/wiki/Subtype#Subtyping_schemes

In Particular to .net concept TextWriter is more generic offer basic functionality to write Streams (StreamWriter) and strings (StringWriter) to a file

REF: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/aa53228f-6d2d-4475-8d7c-8081057f22f9