Global 'Code behind type' setting for front end?
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
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
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
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
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.
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 >>
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).
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 >>
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
Hi Devin,
Yes, you can use the fluent or standard API calls.
Kind regards,
Ivan Dimitrov
the Telerik team
Hi Ivan,
Can you please provide some sample code demonstrating how to do this?
Thanks!
Devin
Hello Devin,
You can see a sample here.
Kind regards,
Ivan Dimitrov
the Telerik team