How to add code-behind code to umbraco templates?
I am getting started with umbraco 4.5.2.
I have my site up and running, and I am designing templates u开发者_StackOverflowsing some ASP.NET controls. How can I respond to events from these controls?For example, I have added a Button to a template. How can I edit the code-behind file to perform some action whenever the button is clicked?
Thank you,
Martin Wiboe
You can actually create fully functional ASP.NET .ascx
Controls, and wrap them in a Macro to display inside your template/page.
Check out this excellent video on how to do this.
Good luck!
Marko
Have a look at the bottom of this blog post.
Quote:
When using Visual Studio, it’s nice to have code-behind files for your templates (at least, that’s how we do stuff). If you create a template in Umbraco, it creates a masterpage without code-behind…
Then you would have to add a code-behind manually, link it with the mark-up and create designer file. That sucks right?
Just do this:
- Create a nested masterpage in VS and use your ‘master’-masterpage as masterpage in the masterpages folder. Lol, there’s a lot of ‘masterpage’ in that sentence hehe. VS creates a masterpage for you with code-behind, sweet!
- VS opens the mark-up of this newly created masterpage, keep it opened!
- Then go to your Umbraco back-end and create a template like you would normally do.
- Give it the same name as you defined in step 1.
- This should create an Umbraco template by using the already created masterpage as file.
- Now return to Visual Studio. It should notify you that the file has changed and gives you the option to reload the file. Reload and then use CTRL+Z to undo the changes made by Umbraco (else the code-behind won’t be linked to the mark-up) and save it.
- You’re done!
There is also this utility that will create the codefiles for you http://umbracocs.codeplex.com/
精彩评论