Thursday, May 27, 2010

Accessing Master page controls from a content page

Today I want to share with you how to use master page control from content page.
Suppose there is a Label on the Master page that we want to write to from the Content page.

1. We must include a MasterType directive at the top of the Content page ASPX file:

<%@ MasterType virtualpath="~/DetailsMaster.master" %>


2. We must include a public function in the Master page that returns a typed reference to the Label:

VB.net

Public Function LabelReference() As Label
' Create a reference to an actual label on the page
LabelReference = lblDetailsItemName
End Function
C#
public Label LabelReference()
{
// Create a reference to an actual label on the page
return lblDetailsItemName;
}

3. We can access the Label from the Content page using the Master syntax:

Master.LabelReference.Text = "Demo text";

Hope that it will help for developer.

No comments:

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...