Friday, March 10, 2017

When to use ScriptLink in SharePoint 2013

Hi Folks,

Some times we will run into situations where our custom js file should load only after the page is ready.

In this kind of scenario's, best thing to use is ScriptLink.

ScriptLink have the ability to specify, when we want the script to load asynchronously after the page is ready. By Default, the ScriptLink will always look for the scripts present in /_LAYOUTS/1033 folder.

<SharePoint:ScriptLink language="javascript" name="MyCustomJS.js" Defer="true" runat="server"></SharePoint:ScriptLink>

MyCustom.js should be present in /_LAYOUTS/1033 folder, if not we will get a SharePoint Error screen.

If you set the "Localizable" property of the ScriptLink to false, you can also reference files outside of /_LAYOUTS/1033/ and just put your path to the "Name" property

<SharePoint:ScriptLink Language="javascript" Localizable="false" Name="/_layouts/JS/MyCustomJS.js" runat="server"></SharePoint:ScriptLink>

With the above approaches, we can load the page first and then load the script file.

Note: Using Defer="False" is basically the same as loading the script with the usual method as below.
<script type="text/javascript" src="/_layouts/1033/MyCustomJS.js"></script>


Hope this helps...

Wednesday, March 8, 2017

Why Javascript works only after launching developer tool bar in IE once

Hi Friends,

This post basically talks about the strange experience which I faced in one of the applications.

Problem Statement:
In Internet Explorer, the Javascript/jQuery is not working until I open the IE Tool bar once.


Solution:
After multiple trial and errors, what I observed is, it's because of the console.log present in my jQuery file.

The console object will only be activated when the IE Dev Toolbar is opened. Prior to that, calling the console object will result as undefined. After the toolbar has been opened, the console will exist (even if the toolbar is subsequently closed), so your console calls will then work.


Hence make sure to remove any Console entries from the JS file during the roll-out of the application.


Hope this helps...

Thursday, February 23, 2017

SharePoint 2010/2013 Display user information using ProfilePropertyLoader

Hi Folks,

This article talks about the best way to get the user profile properties on page.

Sometimes we come across the requirement asking to show the User related information on the page.
Generally we write code by accessing User Information list to get the User related data.

In such cases, rather than writing code SharePoint gives us the provision to read the User data.

SharePoint has something called "ProfilePropertyLoader" control which will be available in any SharePoint page which has the below register tag.

<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Follwing are the tags we need to add to the page inoder to read the current user Name and Email.

User Name
The first line below is needed to load and make the profile properties available.

<SPSWC:ProfilePropertyLoader runat="server"/>

<SPSWC:ProfilePropertyValue PropertyName="FirstName" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>

<SPSWC:ProfilePropertyValue PropertyName="LastName" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>

Email
<SPSWC:ProfilePropertyValue cssClass="loggedin" PropertyName="WorkEmail" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>


Hope this helps...

RELATED POST: How to get current user info using jquery spservices



Popular Posts