Copied to clipboard

Flag this post as spam?

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


  • Eddie Foreman 215 posts 288 karma points
    Jul 12, 2010 @ 13:29
    Eddie Foreman
    0

    Update usercontrol values

    Hi All

    I've a small address box (usercontrol), which is repeated across the site but depending on the page layout, the address box will appear in a different positions. To save the content editor having to update duplicate versions of the address box, I thought a usercontrol would be the best approach.

    From Umbraco, the macro has been added to the homepage template.  Properties have been added to the DataType, so that the usercontrols fields can be updated via the homepage. 

     <umbraco:Macro  Address="[#addressText]" Telephone="[#telText]" Email="[#emailText]" CompanyNo="[#companyText]" runat="server"></umbraco:Macro>

    This approach works fine on the home page, but not on any other pages, where the default property values are loaded from the usercontrol.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text;

    namespace companyAddress
    {
        public partial class companyAddress : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {

                if (!Page.IsPostBack) {
                    addresslbl.Text = _address;
                    telephonelbl.Text = _telephone;

                    StringBuilder emailLink = new StringBuilder();
                    emailLink.Append(string.Format("<a href=\"mailto:{0}\">{0}</a>", _email));
                    emaillbl.Text = emailLink.ToString();

                }
            }

            //properties
            public string Address
            {
                get { return _address; }
                set { _address = value; }
            }
            public string Telephone
            {
                get { return _telephone; }
                set { _telephone = value; }
            }
            public string Email
            {
                get { return _email; }
                set { _email = value; }
            }

            //Properties
            private string _address = "The Street";
            private string _telephone = "01234 567 789";
            private string _email = "[email protected]";

        }
    }

    As you can see there's not much to the usercontrol.  If possible I would like to update the default fields in the usercontrol, from the home page.  And then within each content page template, add the usercontrol as normal using:

    <ef:CompanyAddress ID="addressBox" runat="server" />

    Any advice or pointers would be greatly appericated.

    Umbraco Version:4.0.4.2
    IIS 7
    Asp.Net 3.5

    Thanks

    Eddie

     

     

     

     

  • Eddie Foreman 215 posts 288 karma points
    Jul 12, 2010 @ 18:54
    Eddie Foreman
    0

    Hi All

    All sorted, but just in case anyone needs a similar solution,

    Just need to update the properties in the Macro, to recursive:

     <umbraco:Macro  Address="[$addressText]" Telephone="[$telText]" Email="[$emailText]" CompanyNo="[$companyText]" runat="server"></umbraco:Macro>

    Then added the above to each content template : -)

    Thanks

    Eddie

     

     

Please Sign in or register to post replies

Write your reply to:

Draft