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?
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.).
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
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.
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.
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?
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...
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.
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?
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.).
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
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.
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.
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?
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?
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...
Well yes, if you want an interesting example of that, do check out my Contact Form for Razor package.
Yeah, you can do all that in Razor. Sounds like you want to check out Seb's Razor Contact Form project :)
lol @ same post Dan! ;-) Thanks for the plug!
Thank you, guys. Will definitely take a look at the project.
I think in this instance you can take all the credit :)
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.
is working on a reply...