Code behind on the templates or user controls - what's the easiest way to program?
Hi!
It's never occured to me before, but with the introduction of Umbraco 4 it looks like there's a new way to add custom code to an Umbraco site using code behind files connected to the masterpages/templates(?) Then there's the "old" way - writing user controls.
What do you recommend? In my case I need to add a membership system to a site which enables users to:
sign up
login
logout
recover their password
see their current login status
All this can be taken care of using standard ASP.NET controls. The main purpose is to protect the areas on the site that can only be accessed by members that are logged in, but I will also need to know who is logged in so I can "mark" (id) data that they enter using forms on the site. This data will be stored in custom database tables (outside Umbraco).
If I hadn't used Umbraco as a base for the site, I'd use traditional ASP.NET-pages (.aspx) with code behind files in which I'd put all the logic. In this case I have chosen Umbraco as a site base and I wil also use the membership section in Umbraco to keep track of members. But all the other stuff will be done with custom code and stored in custom database tables.
What do you recommend? Coding user controls or working with code behind files on the templates?
Both are functionally equivalent, either use them directly into your templates or use user controls to embed your login controls. I always use user controls whenever I have the need to subscribe to specific events for these controls or have to handle postbacks from controls on the user control. If I don't need the extra functionality, then I go for template syntax (btw, you don't need the codebehind, you put them directly onto your template); that being said, you can also use inline server side scripts on your templates to handle postback events for your user controls, but that tends to clutter up the syntax
It's always a trade off, but I tend to use the above rule.
As timing would have it...I just finished a pre-beta version of those controls. I can email the package to you if you would like...but I'm not to a point that I feel comfortable uploading it as a package.
Personally I'd go with user controls any day, just because you then have a better level of abstraction on your code - I wouldn't want to clutter my masterpages with functional code, I use them just for making my sites look pretty!
If you want to publish your package on Codeplex or set up your own project page we can then check it out if you mark it as experimental/alpha/beta etc.
Benjamin: I think I will follow your suggestion and use user controls to encapuslate all the .NET code. It just seems easier and I will just have one place to look if I need to alter something.
Chad: I'd love to take a look at the controls you are working on! My email is thomas(at)karnhuset.net.
I found this page very useful for setting up a smooth working environment. I had something similar set up already, but it can be improved. That way I can easily work on the user controls and I get intellisense and all the nifty tools in VS and I can deploy all the files directly when I make a build. :-)
Code behind on the templates or user controls - what's the easiest way to program?
Hi!
It's never occured to me before, but with the introduction of Umbraco 4 it looks like there's a new way to add custom code to an Umbraco site using code behind files connected to the masterpages/templates(?) Then there's the "old" way - writing user controls.
What do you recommend? In my case I need to add a membership system to a site which enables users to:
All this can be taken care of using standard ASP.NET controls. The main purpose is to protect the areas on the site that can only be accessed by members that are logged in, but I will also need to know who is logged in so I can "mark" (id) data that they enter using forms on the site. This data will be stored in custom database tables (outside Umbraco).
If I hadn't used Umbraco as a base for the site, I'd use traditional ASP.NET-pages (.aspx) with code behind files in which I'd put all the logic. In this case I have chosen Umbraco as a site base and I wil also use the membership section in Umbraco to keep track of members. But all the other stuff will be done with custom code and stored in custom database tables.
What do you recommend? Coding user controls or working with code behind files on the templates?
Regards,
Thomas Kahn
Both are functionally equivalent, either use them directly into your templates or use user controls to embed your login controls. I always use user controls whenever I have the need to subscribe to specific events for these controls or have to handle postbacks from controls on the user control. If I don't need the extra functionality, then I go for template syntax (btw, you don't need the codebehind, you put them directly onto your template); that being said, you can also use inline server side scripts on your templates to handle postback events for your user controls, but that tends to clutter up the syntax
It's always a trade off, but I tend to use the above rule.
Hope this helps.
Regards,
/Dirk
As timing would have it...I just finished a pre-beta version of those controls. I can email the package to you if you would like...but I'm not to a point that I feel comfortable uploading it as a package.
Hi Chad,
Personally I'd go with user controls any day, just because you then have a better level of abstraction on your code - I wouldn't want to clutter my masterpages with functional code, I use them just for making my sites look pretty!
If you want to publish your package on Codeplex or set up your own project page we can then check it out if you mark it as experimental/alpha/beta etc.
Benjamin
Benjamin: I think I will follow your suggestion and use user controls to encapuslate all the .NET code. It just seems easier and I will just have one place to look if I need to alter something.
Chad: I'd love to take a look at the controls you are working on! My email is thomas(at)karnhuset.net.
I found this page very useful for setting up a smooth working environment. I had something similar set up already, but it can be improved. That way I can easily work on the user controls and I get intellisense and all the nifty tools in VS and I can deploy all the files directly when I make a build. :-)
Regards,
Thomas
is working on a reply...