AddContent() and GetPage() versus GetTabs() and Execute() in COM ASP API

2 minute read time.
You can render a page using

var myBlock = CRM.GetBlock("opportunitylist");
Response.Write(CRM.GetTabs());
Response.Write(myBlock.Execute());

The important thing here is that the Execute() method of the block generates the HTML that is to be returned to the page. A page generated this way certainly works. The GetTabs() mechanism will create the default tabgroup for the current context at the top of the page and if we wish to override that we can like this:

Response.Write(CRM.GetTabs("opportunity"));

But this mechanism is not the preferred way of creating the output of a Sage CRM ASP page.
Instead the AddContent and GetPage mechanism is the recommended way of assembling the page.

var myBlock = CRM.GetBlock("opportunitylist");
CRM.AddContent(myBlock.Execute());
Response.Write(CRM.GetPage());
//Response.Write(CRM.GetPage("TabGroupName"));

The Execute method of the block generates the page which is passed as a parameter to the eWare AddContent method. The eWare object holds the page passed by the AddContent method in memory. This allows a page to be assembled from many uses of the AddContent() method.

To output the content held by the eWare object, the GetPage method is called. The returned page is passed as an argument to the Write method of the ASP Response object. This method sends HTML output over HTTP to the browser.

An advantage over the previous technique is that the GetPage assumes the output of the tabgroup. Also if a coaching caption is associated with the returned page, and the coaching caption settings are enabled, the displayed ASP page will feature coaching text.

The example component is available to download that creates a new Project entity and supporting pages has an example of the use of coaching text being used in an ASP page. The article "Creating a New Entity using COM API ASP" contains the links to development partners to download the file.

If you are working with ASP pages and you are using the TextPad text editor then there are some code snippets that you can download.

Another reason to use AddContent and GetPage is that the methods

//Update Recent List and refresh Context frame
CRM.SetContext("EntityName", "EntityID");
CRM.GetCustomEntityTopFrame("EntityName");

only work when AddContent and GetPage are used.

Note:
The AddContent and GetPage mechanisms depend on session and context information that are not available within a Self Service environment. So when constructing Self Service pages only the

Response.Write(myBlock.Execute());

is used. The GetTabs can not be used either as this is only for application extension pages and not self service. A discussion of the use of COM objects in Sage CRM Self Service pages can be found in the article, "COM API objects available in Self Service".

It is worth noting that in the .Net API then page rendering mechanism is much more like the AddContent approach described above. To see an example of Sage CRM .NET code click see this introductory article "The .NET API".