Copied to clipboard

Flag this post as spam?

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


  • mauricio lopez 12 posts 33 karma points
    Jul 04, 2010 @ 04:19
    mauricio lopez
    0

    declare var inside template

    Please tell me how can I do this on asp/umbraco ( I come form php workd)

    I need to have a config value on the master template. I need to declare it before all html. And I need to print/echo the value of the var on several parts of the template. I don't need that the var exists outside the template instance.

    Please someone tell me what is the best approach.

     

    regards

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 04, 2010 @ 09:46
    Dirk De Grave
    0

    Hi,

    Could quite easily do that in your master template using the <%%> syntax, but you should explicitely set the type of the variable you're using

    <%
    int myVar;
    protected void Page_Load(object sender, EventArgs e) {
      myVar = 10;
    }
    %>

    and use the variable in your template using the following syntax:

    <%=myVar%>

     

    Hope this helps.

    Regards,

    /Dirk

  • mauricio lopez 12 posts 33 karma points
    Jul 04, 2010 @ 16:15
    mauricio lopez
    0

    Hi dirk.

    It's not working, I recieved a server error. I am sure it's because my lack of knowleget about asp and master pages. My template begins like this:

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <%@ Register Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" TagPrefix="CD" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="head" runat="server">

     

    Where would you put the code to create the var?

     

    regards

     

     

     

    aa

  • Kevon K. Hayes 255 posts 281 karma points
    Jul 04, 2010 @ 22:21
    Kevon K. Hayes
    0

    If I was you I'd check out the .NET macro vid here if you can: http://umbraco.org/documentation/videos/for-developers/foundation/using-net-user-controls next, if you have Visual Studio Express create a new project, add a user control, and put the code above in the Page_Load event (of the Code Behind of the user control)  and every where within your page you need the value to be displayed put it there within an html element.  FYI Umbraco MasterPages are in the Developers section under the Templates Node.  Also go to MSDN.com to brush up on you ASP.NET  Page Event LifeCycle and MasterPage knowledge.

  • dan 29 posts 53 karma points
    Jul 09, 2010 @ 21:59
    dan
    1

    If you want to grab a value from config you can do something like this.

    <%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
    <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                lblConfig.Text = System.Configuration.ConfigurationSettings.AppSettings["config"].ToString();
            }
    </script>
    <html><body><asp:Label id="lblConfig" runat="server"></asp:Label></body></html>

    I hope this helps

    danielcruger.com

Please Sign in or register to post replies

Write your reply to:

Draft