Running Server Side ASP Code in Widgets
Hi all,
Am running into a bit of a stumbling block with a custom widget for displaying blog posts made within SiteFinity (4.2).
All I'd like to be able to do is run some ASP(.NET) code within a widget template- there are a few caveats, namely the templates don't work on the 'code behind model', so all declarations of functions and classes must be done inline.
Josh Morales says you can add a <script runat="server"> tag anywhere within the widget template, however mine get stripped out by SiteFinity when I save the template after editing. I've tried <asp></asp>; <% .. %>;<%@ .. %> tags with no luck.
Does anyone know if this is possible? I'd prefer to keep the code within the template- it's a few simple lines and it would be ridiculously unnecessary for me to write a whole new control when I can see asp working correctly within the template already (the first few lines of definitions).
A pointer would be very much appreciated, thanks in advance for your help!
Can you post your code from the template editor?
I've done this a bunch of times, it should be totally doable
Hi Steve,
can you please take a look at this forum post, I believe you might find it useful. If you need some additional information, please do not hesitate to let us know.
Greetings,
Boyan Barnev
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 Steve,
Cool, glad to hear I'm not going crazy. Apparently there is a security enhancement with Sitefinity 4.2 (and presumably future releases) which now prohibits inline server side code. For those who have the same problem, the key is to use an external, self created control, which can override the default widget template.
Theoretically you should be able to specify a TemplatePath (from the widget, Edit > ControlDefinition > Views > * > TemplatePath) to point at your ascx control, which can contain server side code without issue. This requires deleting the TemplateKey (same place) definition (a GUID associating widget and template).
Now if only I could get Sitefinity to stop re-inserting the TemplateKey whenever I delete it and click save. I suspect it might do this if I have made a code error, although the code I am trying to run works perfectly from VS2010Prem.
Sorry for the late reply, CS5.5 installation (still no native x64 Illustrator!) required the loss of Outlook yesterday afternoon.
Thanks!
Hello Jeff,
We have addressed this i the support thread you have open, for your convenience please find the part of our reply that concerns the current discussion below:
"The problem you are experiencing might be due to a bug that we had in our Sitefinity 4.2 official release, where the configurations settings were not being saved correctly. The fix has been included in our recently released Hotfix 1, can you please try upgrading a copy of your project to this version and check if the same behavior reproduces.
If you still experience any problems after trying the above solutions, I would kindly ask you to map your external template for the corresponding View type from Administration->Settings->Advanced->Controls->ViewMap."
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 >>
Excuse me, Maybe this post is old but I have the same problem as MBA, and I think the answer is: Apparently there is a security enhancement with Sitefinity 4.2 (and
presumably future releases) which now prohibits inline server side code.
For those who have the same problem, the key is to use an external,
self created control, which can override the default widget template. Because I'm using Sitefinity 5.0 and there is still that problem. Am I right? I'm thiking in use javascript in spite of asp .net code as I planned. I say this because the answer marked is Boyan Barne's so I would like to know if that's really the answer.
Thanks.
Shil,
Hi, not sure if you still need it, but this works:
<script type="C#" runat="server">
protected void Page_Load(object sender, EventArgs e)
//blablabla("bla");
</script>
tested on 5.3 with no problems
found it in the comments:
http://www.sitefinity.com/blogs/joshmorales/posts/josh-morales-blog/2011/05/09/running_server-side_code_in_sitefinity_widget_templates
How my company gets code into widget templates:
http://www.sitefinity.com/developer-network/forums/permalink/R31mK6H3QU2Fh6kqXtbhFg