Copied to clipboard

Flag this post as spam?

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


  • MuirisOG 382 posts 1284 karma points
    Jan 21, 2015 @ 17:23
    MuirisOG
    0

    button not working in usercontrol

    I think I may have answered my own question (and forgive me if my terminology is not right).
    I'm using:

    •     an old instance of Umbraco (4.11.3 but I'd imagine this would happen on any version).
    •     WebForms (changed in the umbracoSettings.config)
    •     a usercontrol written in VB


    The steps to recreate my problem are as follows:

    •     create a user control which includes a button, which when clicked, should update a label.
    •     create a macro, which uses the usercontrol.
    •     add the macro to a page in the Editor (i.e. to the maincontent field)
    •     the template used by that page outputs two versions of the content (depending on the language selected)
    •     this template has an umbraco:macro which includes a bit of razor logic
    •       - if the language is English, output the English content
    •       - if the language is Welsh, output the Welsh content


    The problem was that the button didn't work if the maincontent field was output via the umbraco:macro (note that it was displayed).

    It did work if the if I output the field containing the maincontent as an umbraco page field, or with .net logic to check the language.

    It also worked if I put the macro directly into the template.

    My question is why won't the button work in the umbraco:macro code which gets the maincontent field?

    Is it something to do with postback, page events, and razor doing things differently?

    The code is:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/MasterTemplate.master" AutoEventWireup="false" %>

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderMain" runat="server">

            <h2><umbraco:Macro runat="server" language="cshtml">@((Session["lang"].ToString() == "cy") ? @Model.pagetitle_cy : @Model.pagetitle)</umbraco:Macro></h2>

            <!-- This works -->
            <umbraco:Item field="maincontent" runat="server" />

            <!-- This works -->
            <% if (Session["lang"].ToString() == "cy") { %>
                    <span>
                    <p>Welsh</p>
                    <umbraco:Item field="maincontent_cy" runat="server" />
                    </span>
            <% } %>
            <% else { %>
                    <span>
                    <p>English</p>
                    <umbraco:Item field="maincontent" runat="server" />
                    </span>
            <% } %>

            <!-- This works -->
            <umbraco:Macro Alias="nptImport" runat="server"></umbraco:Macro>

            <!-- This doesn't work -->
            <umbraco:Macro runat="server" language="cshtml">
                    @((Session["lang"].ToString() == "cy") ? @Model.maincontent_cy : @Model.maincontent)
            </umbraco:Macro>


    </asp:Content>
Please Sign in or register to post replies

Write your reply to:

Draft