Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Jan 31, 2014 @ 13:25
    dominik
    0

    Use webforms in MVC

    Hello,

    We are planing to switch from webforms to MVC rendering engine.

    As we have a lot of existing usercontrols developed as webforms we wanted to know if it is possible to reuse them and changing them step by step to MVC?

    Or do we have to switch all our controls to MVC first?

    The controls are developed as C# controls which are currently placed in the /usercontrols folder.

    Changing the masterpages to Views should be possible by using the cheatsheet I suppose.

    Is there any way to use the already developed webform usercontrols in the new MVC project?

    Thanks

     

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 31, 2014 @ 14:42
    Martin Griffiths
    0

    Hi Dominik

    I've done some of the conversion process, so hopefully can shed a little light.

    I came across a blog recently http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx which discusses the two project types working together as one! 

    From my conversion experience I have found Umbraco seems to take on a similar Chameleon like purpose!

    My master pages (templates) do indeed continue to function alongside the MVC view counterparts. Although I'm not entirely sure how much of the ASP.net Page Lifecycle and event model continues to remain intact.

    Personally I tackled my masterpages and a couple of user controls we had in place first. All of our masterpage templates shell out to XSLT, as it was (and continues to be) a very modular way of breaking content into component parts. The good new is XSLT remains 100% compatible and we will slowly work through converting these over a period of time.

    Regards

    Martin

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 31, 2014 @ 14:44
    Martin Griffiths
    0

    Worth adding that debugging pages becomes a truck load easier in C# (razor) when compared to XSLT!

  • dominik 711 posts 733 karma points
    Jan 31, 2014 @ 15:54
    dominik
    0

    Hi martin,

    THanks for your response.

    Currently i am not talking about masterpages as I already read some threads that using masterpages and views in parallel is support in umbraco. I feel also translating a masterpage to a view is not so complex.

    But how it behaves with complex webforms usercontrols which exists as a umbraco macro?

    Can this usercontrols be reused?

    e.g. we are having a Umbraco macro called "CustomerSupport" which is pointing to a ascx file which is written as a webform. Now we are trying to place this usercontrol on a mvc view template. Will this work or do we have to transform each of our usercontrol to a MVC control first.

    All of these usercontrols are ascx files which are developed by using webforms

    Thanks

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 31, 2014 @ 16:00
    Martin Griffiths
    0

    Hi Dominik

    Yea, that's the bit i'm not entirely sure on as I converted my user controls straight away. It's highly likely they will continue to work as long as they're only being used with your existing masterpages. You definitely cannot have an MVC view call a usercontrol because there's no page lifecycle and event model.

    Simply turn the MVC switch on and see if everything continues to function. It's the only way to know for sure.

    If all is good, only switch out your masterpage templates to views that dont have user controls, unless of course, you intend to convert them at the same time.

    Regards

    M.

     

  • dominik 711 posts 733 karma points
    Jan 31, 2014 @ 16:03
    dominik
    0

    hi martin,

    This means if we want to use MVC instead of masterpages we have to switch all controls to MVC?

    All our masterpages are nested and including usercontrols. So there is no masterpage which does not include a usercontrol.

    Another idea would be to create new templates for the new usercontrols and keep the old masterpages for the old ones. Will this work?

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 31, 2014 @ 17:30
    Martin Griffiths
    0

    Hi Dominik

    If ALL of your masterpages have usercontrols with codebehind in them, then it looks like you're stuck without doing a complete conversion.

    If this is too much for you, it would be better to be pragmatic and leave your old code in-place and start building new templates as views & partials going forward. It will leave you with some legacy code that may need attention now and then though.

    Webforms will be around for some time yet though, and it continues to receive significant changes and updates from Microsoft. XSLT/XPath on the other hand is (as far as Microsoft is concerned) a dead technology. Within ASP.net it never got further than version 1!

    Its worth bearing in mind the use of MVC over Webforms is more a matter of preference than an absolute requirement to stay ahead. Of course there are many benefits to using MVC over Webforms, one in particular is it's much easier to write clean, client side orientated code against MVC than it is with Webforms.

    Despite the pros and cons of both, I still enjoy working with the event model but MVC is a better fit for modern web development frameworks.

    Martin.

  • Syed Ahsan 4 posts 53 karma points
    Jun 16, 2014 @ 09:37
    Syed Ahsan
    0

    Hi Dominik!

      Macro works fine in both cases either MVC or Webforms rendring engine. They are independed of the way they were created (UserControls, Scripts, XSLT).
    So i thinks that they should work fine if don't have any dependencies on any page or controls. 

Please Sign in or register to post replies

Write your reply to:

Draft