Copied to clipboard

Flag this post as spam?

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


  • UmbracoNovice 7 posts 27 karma points
    Nov 17, 2011 @ 18:49
    UmbracoNovice
    0

    Razor scripts vs User Controls

    I like a lot using Razor and .cshtml files but I'm wondering if there are cases where I can't accomplish a task with it and need to switch to .NET user control?

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Nov 17, 2011 @ 18:52
    Sebastiaan Janssen
    0

    Razor is HTML mixed with a bit of C#. As far as I know you can not render any usercontrols directly in a Razor file. So if you want to do a form and expect to use ASP.NET webforms controls then you cannot do it in Razor (so that's: no updatepanel, repeaters, etc.).

  • Anthony pj 40 posts 63 karma points
    Nov 17, 2011 @ 18:55
    Anthony pj
    0

    bit of a open ended question , I think you will get a better response from the community if you try and ask something more specific question. Members are usually more then happy to help where they can, great advantage for us newbies.

     

    o just read response you got... seems i missed the point of the question lol i thought you were asking if there are cases where you should use a usercontrol over a approach using razor ? o well

  • UmbracoNovice 7 posts 27 karma points
    Nov 17, 2011 @ 18:57
    UmbracoNovice
    0

    Sorry for the confusion but I meant in what cases do I have to use Macro with .NET User Control vs Macro with Razor script file?  So basically I want to find out what can't be accomplished by Razor's Macro e.g. Form submit. Form validation, Pagination, Ajax, Sorting etc.

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Nov 17, 2011 @ 19:04
    Sebastiaan Janssen
    0

    They can all be accomplished with a Razor macro, but not through webforms controls. So you will mostly be implementing these things in pure html and javascript.

  • UmbracoNovice 7 posts 27 karma points
    Nov 17, 2011 @ 19:57
    UmbracoNovice
    0

    I guess Pagination and Sorting can be done through the query string so no javascript would be needed.

    I'm wondering if it's possible to show/hide Macros from a master page event and maybe event set some Macro parameters or variables?

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Nov 17, 2011 @ 20:05
    Sebastiaan Janssen
    0

    You can send parameters into a Razor macro for sure. But I'm not sure what you mean, maybe you can give a specific example of what you're trying to achieve?

  • UmbracoNovice 7 posts 27 karma points
    Nov 17, 2011 @ 20:39
    UmbracoNovice
    0

    For example I have a form and show macro with  the input fields initially and hide 'thank you' macro. On the form submit I validate the data and if it's valid hide the 'fields' macro and show 'thank you' macro. Or I can send a parameter to macro to switch the divs to display...

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Nov 17, 2011 @ 21:25
    Sebastiaan Janssen
    0

    Well yes, if you want an interesting example of that, do check out my Contact Form for Razor package.

  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Nov 17, 2011 @ 21:25
    Dan Diplo
    0

    Yeah, you can do all that in Razor. Sounds like you want to check out Seb's Razor Contact Form project :)

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Nov 17, 2011 @ 21:31
    Sebastiaan Janssen
    0

    lol @ same post Dan! ;-) Thanks for the plug!

  • UmbracoNovice 7 posts 27 karma points
    Nov 17, 2011 @ 21:39
    UmbracoNovice
    0

    Thank you, guys. Will definitely take a look at the project.

  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Nov 17, 2011 @ 21:40
    Dan Diplo
    0

    I think in this instance you can take all the credit :)

  • Rodion Novoselov 694 posts 859 karma points
    Nov 18, 2011 @ 13:51
    Rodion Novoselov
    0

    Hi. In my opinion using razor should be prefered over user controls looking forward to U-5 where razor is going to become a mainstream tool of creating UI. And my other point (that's however just a matter of personal taste) is that why I like umbraco - it's a high level of control over the HTML generated. When you implement something as a user control in umbraco you always lose this control over rendering to some amount, since you have to fallback to the web-form page model with a viewstate etc.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies