Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Kahn 602 posts 506 karma points
    Jan 06, 2010 @ 16:31
    Thomas Kahn
    0

    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?

    Regards,
    Thomas Kahn

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 06, 2010 @ 17:02
    Dirk De Grave
    0

    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

  • Chad Rosenthal 272 posts 474 karma points
    Jan 06, 2010 @ 17:31
    Chad Rosenthal
    1

    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.

  • Jamie Howarth 306 posts 773 karma points c-trib
    Jan 06, 2010 @ 17:44
    Jamie Howarth
    0

    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

  • Thomas Kahn 602 posts 506 karma points
    Jan 06, 2010 @ 19:42
    Thomas Kahn
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft