Copied to clipboard

Flag this post as spam?

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


  • James Timms 2 posts 22 karma points
    Mar 27, 2013 @ 11:59
    James Timms
    0

    Button not Firing when used in UserControl Displayed with Razor

    Hi,

    I'm fairly new to Umbraco, so just trying a few things out at the moment. Basically we've got a one-to-one multi language website that uses a Razor shorthand "If" to display the appropriate content depending on what langauage is stored in the Session i.e.

    <umbraco:Macro ID="Macro4" runat="server" language="cshtml">
         @((Session["lang"].ToString() == "cy") ? @Model.mainContent_cy : @Model.mainContent)

    umbraco:Macro>

    Within mainContent, I've created a simple macro that uses a usercontrol with a solitary asp.net label and a button. When the button its clicked, the label updates to show the current time.

    Using this technique above, the right content with the usercontrol is displayed as expected. However when I click the button, PostBack is not firing, the page just seems to reload.

    However, if I explicitly include the mainContent content, everything looks the same but the button DOES fire as expected i.e.

    <umbraco:Item ID="Item5" runat="server" field="mainContent" />

    Am I overlooking something, or is there a better way rather than the Razor shorthand "If" to display the appropriate content?

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 27, 2013 @ 18:42
    Jan Skovgaard
    0

    Hi James and welcome to our :)

    What version of Umbraco are you using? And is the rendering engine set to use MVC?

    If so that's probably the reason why you can't get it to work.

    Looking forward to hearing from you.

    /Jan

  • James Timms 2 posts 22 karma points
    Mar 28, 2013 @ 10:10
    James Timms
    0

    Hi Jan,

    Thanks for your reply. I'm using umbraco v 4.11.3. How can I tell if the rendering engine is set to use MVC? I've only started recently with Umbraco so it's all fairly new to me.

    Thanks for your help

    James

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 29, 2013 @ 11:56
    Jan Skovgaard
    0

    Hi James

    Ok then I guess you're not using MVC rendering mode.

    But you can check it in the umbracoSettings.config file in the config folder. In here there are a lot of different settings. The one you should look for in this case is <defaultRenderingEngine>webforms</defaultRenderingEngine> - In your case it probably just looks like this, which is fine.

    It's just that if it was set to MVC that would probably be the reason why your user control did not work when posting.

    Would it be possible for you to try and refactor the Razor calling your user control to use a XSLT macro instead? Must admit that I can't remember if there can be some issues with posting a user control when it's rendered from Razor.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft