Tuesday, May 22, 2012

Adding Javascript to a SharePoint Master or Layout page

If you need to add javascript to a SharePoint Master or Layout page, add the script to the Head section or PlaceHolderAdditionalHead content area. Be sure to include the  _spBodyOnLoadFunctionNames.push function so your function is added to the OnLoad method.

<script type="text/javascript">
function UpdateCampusAddress()
{
if (window.location.href.toLowerCase().startsWith("http://<site name>/"))
{
document.getElementById('CampusAddress').innerHTML = "Williams Campus";
}
else if (window.location.href.toLowerCase().startsWith("http://<site name>/"))
{
document.getElementById('CampusAddress').innerHTML = "Sun Lakes Campus";
}
}
_spBodyOnLoadFunctionNames.push("UpdateCampusAddress");
</script>

Tuesday, May 15, 2012

Empty dataset template for DataList control

There is no Empty dataset Template for the DataList control. To display a message in the DataList control if your dataset is empty, define a HeaderTemplate and set the visibility based upon the item count as shown below:
 
<asp:DataList runat="server" id="DataList1" DataSourceID="spDataSource1">
<HeaderTemplate>
<span style="font-style:italic;color:#181818">
<asp:Label ID="lblEmpty" Text="No Events" runat="server" Visible='<%# DataList1.Items.Count==0 %>'/>
</span>
</HeaderTemplate>
<ItemTemplate>
<p>
...
</p>
</ItemTemplate>
</asp:DataList>