Question

I am getting started with umbraco 4.5.2.
I have my site up and running, and I am designing templates using 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

Was it helpful?

Solution

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:

  1. 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!
  2. VS opens the mark-up of this newly created masterpage, keep it opened!
  3. Then go to your Umbraco back-end and create a template like you would normally do.
  4. Give it the same name as you defined in step 1.
  5. This should create an Umbraco template by using the already created masterpage as file.
  6. 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.
  7. You’re done!

OTHER TIPS

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

There is also this utility that will create the codefiles for you http://umbracocs.codeplex.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top