I have some legacy Webforms code that I need to integrate into my standard Umbraco 7.2 project, with Fanoe starter kit. I've been led to believe (from docs, videos etc) that this was easily achievable by rolling it up into a usercontrol and embedding it as a macro. As I've dived further into it looks like they won't be able to be used with postbacks at all (or can they?). Even ensuring that the usercontrol has a form and scriptmanager doesn't work... it will display fine, but buttons etc. don't do anything.
I can't spend any more time trying to figure it out, can anyone give me a definitive "No it won't work" or "Of course it can, if you do XYZ"?
In the meantime I'm going to create a separate aspx page to hold the control (with appropriate exclusions in web.config), but that does mean running a parallel version of the master template (one as .cshtml, the other as .Master) and trying to convert all my current header & footer partial views to ascx usercontrols. Is there a way to include the razor partial view in my .Master page somehow? If I can't include them then how do I access things like CurrentPage.Site() and recurse through the childpages in the codebehind? The goal being to have the navigation header & footer still coming out of Umbraco, regardless of which template is displaying it.
For instance, how would I replicate this razor partial in aspx? (MainNavigation.cshtml from Fanoe starter kit)
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var home = CurrentPage.Site(); }
@if (home.Children.Any())
{
@* Get the first page in the children *@
var naviLevel = home.Children.First().Level;
@* Add in level for a CSS hook *@
<ul class="level-@naviLevel">
@* For each child page under the home node *@
@foreach (var childPage in home.Children)
{
if (childPage.Children.Any())
{
<li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
@if(childPage.DocumentTypeAlias == "LandingPage")
{
<span>@childPage.Name</span>
@childPages(childPage.Children)
}
else
{
<a href="@childPage.Url">@childPage.Name</a>
}
</li>
}
else
{
<li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
<a href="@childPage.Url">@childPage.Name</a>
</li>
}
}
</ul>
}
@helper childPages(dynamic pages)
{
@* Ensure that we have a collection of pages *@
if (pages.Any())
{
@* Get the first page in pages and get the level *@
var naviLevel = pages.First().Level;
@* Add in level for a CSS hook *@
<ul class="sublevel level-@(naviLevel)">
@foreach (var page in pages)
{
<li>
<a href="@page.Url">@page.Name</a>
@* if the current page has any children *@
@if (page.Children.Any())
{
@* Call our helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
}
}
I should say I have created a test aspx page with a umbracoReservedUrls exclusion and that IS working fine. I'm really just not sure how to dig into the Umbraco side of things from there. It looks like I need to explore Umbraco.Core.Models further but I'm not exactly sure if that's right.
In short regarding the user controls, No it won't work! You can render content from user controls but when you need to submit something that is not possible. That's one of the things I remember from the level 2 course I attended 2 years ago :)
I think you should try thinking about converting from masterpages to mvc rather than spending time on making some of the masterpage stuff work.
But perhaps the thing that you should consider is to change the template engine from MVC to Webforms in the /config/umbracoSettings.config file?
Thanks for the quick reply! It's good to get a definitive answer on the user control thing so I don't keep wondering :)
I already have the MVC master and navigation working... I actually converted it from a standard .master page and tied in all the Umbraco pieces with the help of the Fanoe starter kit. The site itself is working great, but the problem is trying to integrate a legacy webforms page and adding in the umbraco navigation bits so both templates look identical. I really can't convert the webforms page itself to MVC as it's actually a page with half a dozen user controls with advanced functionality that has been developed over a number of years - so it's not a simple matter to convert that to MVC. I would like to do that one day, but for now I just need it to live inside the Umbraco site on a separate section.
It looks like this is pretty straightforward - I just needed to add this reference:
using Umbraco.Web;
And then in a suitable function I can do an almost direct conversion of the MVC with Razor I posted before (simplified example below):
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var home = umbracoHelper.Content(1069);
if (home.Children.Any())
{ litPages.Text = "<ul class=\"left\">";
//For each child page under the home node
foreach (var childPage in home.Children)
{
if (childPage.Where("Visible"))
{ litPages.Text += "<li>"; litPages.Text += "<a href=\"" + (string)childPage.navigationLinkUrl.url + "\"" + "target=\"" + childPage.navigationLinkUrl.target + "\">" + childPage.Name + "</a>"; //rest of the code to get page children litPages.Text += </li>; } } litPages.Text += "</ul>"; }
The only issue is the hard-coded node id (1069) which I'm trying to figure out now...
UPDATE: Don't use the code I provided above in a multi-site arrangement as it does not work!!! It will return the same Home NodeID instead of the Home of the current site.
@Vijay - no, I had to recreate everything using standard webforms. So now I have to maintain separate MVC and Webforms code :\ It would be easy if everything is webforms (as you can switch Umbraco to just use that) but mixing them is a little problematic. Maybe other people have better ideas, but from my experience these forums are pretty dead - so don't expect anyone else to really answer.
Webforms ascx control or aspx page in MVC install
I have some legacy Webforms code that I need to integrate into my standard Umbraco 7.2 project, with Fanoe starter kit. I've been led to believe (from docs, videos etc) that this was easily achievable by rolling it up into a usercontrol and embedding it as a macro. As I've dived further into it looks like they won't be able to be used with postbacks at all (or can they?). Even ensuring that the usercontrol has a form and scriptmanager doesn't work... it will display fine, but buttons etc. don't do anything.
I can't spend any more time trying to figure it out, can anyone give me a definitive "No it won't work" or "Of course it can, if you do XYZ"?
In the meantime I'm going to create a separate aspx page to hold the control (with appropriate exclusions in web.config), but that does mean running a parallel version of the master template (one as .cshtml, the other as .Master) and trying to convert all my current header & footer partial views to ascx usercontrols. Is there a way to include the razor partial view in my .Master page somehow? If I can't include them then how do I access things like CurrentPage.Site() and recurse through the childpages in the codebehind? The goal being to have the navigation header & footer still coming out of Umbraco, regardless of which template is displaying it.
For instance, how would I replicate this razor partial in aspx? (MainNavigation.cshtml from Fanoe starter kit)
I should say I have created a test aspx page with a umbracoReservedUrls exclusion and that IS working fine. I'm really just not sure how to dig into the Umbraco side of things from there. It looks like I need to explore Umbraco.Core.Models further but I'm not exactly sure if that's right.
Hi Schlubadub
In short regarding the user controls, No it won't work! You can render content from user controls but when you need to submit something that is not possible. That's one of the things I remember from the level 2 course I attended 2 years ago :)
I think you should try thinking about converting from masterpages to mvc rather than spending time on making some of the masterpage stuff work.
But perhaps the thing that you should consider is to change the template engine from MVC to Webforms in the /config/umbracoSettings.config file?
/Jan
Hi Jan,
Thanks for the quick reply! It's good to get a definitive answer on the user control thing so I don't keep wondering :)
I already have the MVC master and navigation working... I actually converted it from a standard .master page and tied in all the Umbraco pieces with the help of the Fanoe starter kit. The site itself is working great, but the problem is trying to integrate a legacy webforms page and adding in the umbraco navigation bits so both templates look identical. I really can't convert the webforms page itself to MVC as it's actually a page with half a dozen user controls with advanced functionality that has been developed over a number of years - so it's not a simple matter to convert that to MVC. I would like to do that one day, but for now I just need it to live inside the Umbraco site on a separate section.
Cheers,
Schlubadub
I really just need to know how to recurse through all the site nodes using webforms code...
It looks like this is pretty straightforward - I just needed to add this reference:
And then in a suitable function I can do an almost direct conversion of the MVC with Razor I posted before (simplified example below):
The only issue is the hard-coded node id (1069) which I'm trying to figure out now...
... which is resolved by using:
UPDATE: Don't use the code I provided above in a multi-site arrangement as it does not work!!! It will return the same Home NodeID instead of the Home of the current site.
Use this: https://our.umbraco.org/forum/developers/api-questions/65075-Root-Home-Node-incorrect-in-Multi-Site-Setup
Hi Schlubadub,
I am having a similar issue as you had.
Did you get MVC and a webform to work together along with MVC header and footer?
Any help would be great.
Thanks,
Vijay
@Vijay - no, I had to recreate everything using standard webforms. So now I have to maintain separate MVC and Webforms code :\ It would be easy if everything is webforms (as you can switch Umbraco to just use that) but mixing them is a little problematic. Maybe other people have better ideas, but from my experience these forums are pretty dead - so don't expect anyone else to really answer.
is working on a reply...