This is a migrated thread and some comments may be shown as answers.

Sitefinty Page: how to access Code Behind Type (CodeBehindType))

5 Answers 120 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
omhoge
Top achievements
Rank 1
omhoge asked on 16 Mar 2016, 01:00 PM

How do you set the CodeBehindType property for a Sitefinity Page in C# code?

 

We are importing a lot of legacy content into Sitefinity, currently we trigger the import via a Sitefinity Page with our custom code in its Code Behind Type option in the Sitefinity editor.

The imported pages are inheriting that CodeBehindType, and we need reset that property during the import.

 

Thanks for considering my question.

5 Answers, 1 is accepted

Sort by
0
Pavel Benov
Telerik team
answered on 18 Mar 2016, 12:55 PM
Hello John,

As you might know Sitefinity's pages consist of 2 objects - e.g. PageNode (for navigation) and PageData (for presentation). The CodeBehindType property is available from the PageData object of a page:

var pd = new PageData();
pd.CodeBehindType = "Some.Type.Here";

You can check our Documentation for detailed CRUD API samples with Pages (both PageNode and PageData objects included) in order to alter your code to fit your requirement.

http://docs.sitefinity.com/for-developers-query-pages

Regards,
Pavel Benov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
0
omhoge
Top achievements
Rank 1
answered on 18 Mar 2016, 07:09 PM

Thank you very much Pavel.

Unfortunately that did not work with the imported content type:

DynamicContent legacyPageContentItem = this.DynamicModuleManager.CreateDataItem(this.LegacyPageContentType);
            legacyPageContentItem.CodeBehindType

errors out.

These are not built-in SF pages, but custom content types for pages from the legacy system,  and they still call the importing page's code behind when they are previewed, so they re-start the import and delete themselves.  They will not display in a page with the widget for listing and display content that the module builder created.  that's why I'm trying to clear out that code behind property.

 

0
Pavel Benov
Telerik team
answered on 23 Mar 2016, 12:27 PM
Hi John,

From what I am understanding you have a Sitefinity page, where you have used its CodeBehindType property to set a code behind file. In the code behind file (probably Page_Load event) you are using API to get your legacy content and store it in Sitefinity. Is this assumption correct so far?

In your last reply I can see that you are using DynamicContent type, which is the type used by modules created through Module builder, so I assume you are storing the legacy content into a Dynamic module (from Module builder).

It is important to note here that DynamicContent type does not have CodeBehindType property for it is a model type of object. 

Can you tell me on which page have you placed the automatically generated widget for your Dynamic module? If it is placed on the page which you use to import content, please move it to a different page and see if the code is executed again when you preview.

If it still does, then go to Content->Your module->Pages where items like this are published. If the page which you use to import content is at the top of the list with priority 1, move it to the bottom (using the Actions menu).

More information on this can be found here:

http://docs.sitefinity.com/locations-of-content-items-canonical-urls

Regards,
Pavel Benov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
0
omhoge
Top achievements
Rank 1
answered on 24 Mar 2016, 12:27 PM
Thank you, Pavel, for that information, most helpful.
0
Pavel Benov
Telerik team
answered on 25 Mar 2016, 08:04 AM
Hi John,

I am glad I could help.

Regards,
Pavel Benov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
Tags
General Discussions
Asked by
omhoge
Top achievements
Rank 1
Answers by
Pavel Benov
Telerik team
omhoge
Top achievements
Rank 1
Share this question
or