Copied to clipboard

Flag this post as spam?

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


  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jul 29, 2014 @ 09:31
    Jimmy Dan Mortensen
    0

    Razor inline Macro in usercontrol and using data from SQL datasource

    Hi,

    In short the question is: How do I use a SQL datasource field (called UmbracoID) inside the inline-razor macro?

    I have created an usercontrol in VB, and now I would like to use some inline razor macroing, but I can't seem to find any examples on how to use an external parameter (such as SQL datasource) inside the macro.

    Here is my present code (If i hardcode the ID it works):

    <asp:SqlDataSource ID="dsKontaktinfo" runat="server" ConnectionString="<%$ ConnectionStrings:ServiceBeregnerSQLConnectionString %>" SelectCommand="sp_Kontaktinfo_Select" SelectCommandType="StoredProcedure">
    <SelectParameters>
    <asp:Parameter Name="AfdelingID" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>

    <asp:FormView ID="fvKontaktinfo" runat="server" DataSourceID="dsKontaktinfo">
    <ItemTemplate>
    <h2>Ejner Hessel, <%#Eval("Navn")%> A/S</h2>
    <p><%#Eval("Adresse")%></p>
    <p><%#Eval("Postnr")%> <%#Eval("City")%></p>
    <umbraco:Macro runat="server" language="cshtml">
    @Library.NodeById(<%#Eval("UmbracoID")%>).serviceBeregnerAabningstider
     </umbraco:Macro>
    </ItemTemplate>
    </asp:FormView>

    Basically I have a database which contains a table with all my departments. In this table I have added an integer field containing the node-number for each department relative to my umbraco-pages. What I wanna do is to use this int, so that I can use the "serviceBeregnerAabningstider" field from Umbraco.

    The error i am recieving is this:

    Error reading usercontrols/Serviceberegner/Serviceberegner.ascx

    The following list shows the Public Properties from the Control. By checking the Properties and click the "Save Properties" button at the bottom, umbraco will create the corresponding Macro Elements.

    System.Web.HttpParseException (0x80004005): Code blocks are not supported in this context. --->

    and it goes on :-)

    Any pointers would be greatly appreciated (and yes I am a noob), so even if it is obvious please help me :-)

    /Regards
    Jimmy

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 29, 2014 @ 12:14
    Jeroen Breuer
    0

    Could you to to add RenderEvent="PreRender" to the macro. By default it runs preinit and the Eval("UmbracoID") might not be ready yet.

    Jeroen

  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jul 29, 2014 @ 12:18
    Jimmy Dan Mortensen
    0

    I tried this:

      <umbraco:Macro runat="server" language="cshtml" RenderEvent="PreRender">
        @Library.NodeById(<%#Eval("UmbracoID")%>).serviceBeregnerAabningstider
      </umbraco:Macro>

    And it still tells me that code block is not allowed.Have I done i correctly?

    /Regards
    Jimmy

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 29, 2014 @ 12:32
    Jeroen Breuer
    0

    Maybe you should create a separate razor macro file and pass the value as a parameter to that: http://our.umbraco.org/documentation/reference/templating/macros/razor/using-macro-parameters

    Also make sure that your Razor macro file still has the RenderEvent="PreRender".

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft