Copied to clipboard

Flag this post as spam?

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


  • schlubadub 102 posts 617 karma points
    Apr 01, 2015 @ 11:37
    schlubadub
    0

    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)

    @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>
            }
    }

     

  • schlubadub 102 posts 617 karma points
    Apr 01, 2015 @ 11:41
    schlubadub
    0

    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.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 01, 2015 @ 11:44
    Jan Skovgaard
    0

    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

  • schlubadub 102 posts 617 karma points
    Apr 01, 2015 @ 11:54
    schlubadub
    0

    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 

  • schlubadub 102 posts 617 karma points
    Apr 01, 2015 @ 15:53
    schlubadub
    0

    I really just need to know how to recurse through all the site nodes using webforms code...

  • schlubadub 102 posts 617 karma points
    Apr 02, 2015 @ 05:22
    schlubadub
    100

    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...

  • schlubadub 102 posts 617 karma points
    Apr 02, 2015 @ 10:03
    schlubadub
    0

    ... which is resolved by using:

    int rootNodeID = umbracoHelper.ContentAtRoot().FirstOrDefault().Id
  • schlubadub 102 posts 617 karma points
    May 26, 2015 @ 07:11
    schlubadub
    0

    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

  • Vijay Kumar Rajagopalan 4 posts 24 karma points
    Jun 03, 2015 @ 18:20
    Vijay Kumar Rajagopalan
    0

    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

  • schlubadub 102 posts 617 karma points
    Jun 07, 2015 @ 15:33
    schlubadub
    0

    @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.

Please Sign in or register to post replies

Write your reply to:

Draft