Tuesday, February 22, 2011

Execute a JavaScript onload() function in SharePoint page

In SharePoint, most of the time master page contains the BODY tag, now if you want to add your JavaScript function on body onload() then there is a workaround for it. SharePoint provides the "_spBodyOnLoadFunctionNames" array. When the body is loaded, the onload event handler executes each function whose name is contained in this array.

<script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("FunctionName");
    function FunctionName()
    {
      // Code goes here...
    }
script>

This array is basically a part of init. If you open the JavaScript file, you will notice the page onLoad event is handled by function _spBodyOnLoadWrapper, which further calls ProcessDefaultOnLoad, and this function executes all the function names added in array _spBodyOnLoadFunctionNames.

Monday, February 14, 2011

Out of box SharePoint Development

DO NOT write code if you don't have to.

I am a developer and I love coding. However, I find that not to write code, when the requirements can be fulfilled using OOB, is the way to make a SharePoint development project successful.
Yes, go codeless in a SharePoint development project.

Here are pros for going OOB:
  1. No need to write code
  2. No need to debug code
  3. No need to test code
  4. No need to optimize code, such as cache, log, exception handling, etc.
  5. Easier to understand (not always)
  6. Easier to deploy (not always)
  7. Shorter development cycle
  8. Save time and $
And of course there are cons:
  1. Harder to debug and test
  2. Limited options for optimization
  3. May not be feasible
  4. May be harder to deploy

Future of the SharePoint is OOB only, Sandbox solutions in SharePoint 2010 is the first step towards it.