More in this section

Forums / Developing with Sitefinity / Global 'Code behind type' setting for front end?

Global 'Code behind type' setting for front end?

12 posts, 0 answered
  1. John
    John avatar
    61 posts
    Registered:
    08 Jun 2012
    22 Jun 2011
    Link to this post
    Hello,

    Is there any way to globally specify the "Code behind type" to use for all of our frontend pages? We are able to successfully set this on a page-by-page basis, but maintenance is a bit of a challenge this way.

    We searched through the Page settings in the Advanced Administration Settings section, but did not see any similar setting there.

    Thank you for any insight!

    Regards,
    John
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Jun 2011
    Link to this post
    Hi John,

    All Sitefinity pages are dynamically created and custom and user controls are your presentation layer. You can create a base class for your custom controls and inherit from it. Another option is a custom master page ( template) which has code behind where you add common logic.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. John
    John avatar
    61 posts
    Registered:
    08 Jun 2012
    22 Jun 2011
    Link to this post
    Hey Ivan,

    Wow - late night!

    We tried the master page route, but were having difficulty accessing the properties there from our custom controls. We did not see how to add the equivalent of "MasterType" that would allow us to directly access our master page properties. I know we can try casting, but with multiple levels of master pages (nested) this was not ideal because we had to check Page.Master, and Page.Master.Master, etc.

    In the Pages admin section, Title & Properties, it allows us to set a "Code behind type" for each page. This works well for us, and we were just wondering if there was any global way to set this value.

    Thanks, again!

    Regards,
    John
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Jun 2011
    Link to this post
    Hello John,

    Yes code behind for pages would work. All you need is a class that inherits from System.Web.UI.Page which allows you to inject logic overriding some of the base methods.

    There is no configuration you can use to set default value, but you can add a helper text from the configuration.

    You can add help text from the configuration

    ContentView
    • Controls
      • FrontendPages
        • Views
          • FrontendPagesListView
          • FrontendPagesCreate  
            • Sections
              • AdvancedOptionsSection
                • Fields
                  • CodeBehindType


    Regards,
    Ivan Dimitrov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  5. John Tolar
    John Tolar avatar
    87 posts
    Registered:
    07 May 2003
    23 Aug 2011
    Link to this post
    This is great information, but for some reason when I add the value to the Value field and hit save, it says it saved but it does not retain the value.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    26 Aug 2011
    Link to this post
    Hello John,

    Please make sure that you modified FrontendPagesEdit config section as well.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  7. John Tolar
    John Tolar avatar
    87 posts
    Registered:
    07 May 2003
    26 Aug 2011
    Link to this post
    I did both sections, the problem is when I go back into the config section I just modified the value is not retained even though it said it was saved. I checked to make sure that my config files were not read only (I have seen that before).
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Sep 2011
    Link to this post
    Hi John Tolar,

    You can change the Example resource key which is used to show helper text below the input field of the custom code behind.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  9. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    12 Oct 2011
    Link to this post
    Hi Ivan,
    I'd like to add a custom code behind to several pages of an existing site.  Can I code this using the Fluent API?

    Thanks!
    Devin
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Oct 2011
    Link to this post
    Hi Devin,

    Yes, you can use the fluent or standard API calls.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  11. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    12 Oct 2011
    Link to this post
    Hi Ivan,
    Can you please provide some sample code demonstrating how to do this?

    Thanks!
    Devin
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Oct 2011
    Link to this post
    Hello Devin,

    You can see a sample here.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
12 posts, 0 answered