Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 8 of 8

Thread: Using Skin Tokens in User Controls

  1. #1
    cscooper2000 is offline Junior Member
    Join Date
    Aug 2009
    Posts
    3

    Default Using Skin Tokens in User Controls

    I've set up a template and specified a different hometemplate. Because the menus and footers should be the same for both templates, I'm using two user controls: GlobalHeader.ascx and GlobalFooter.ascx. Everything has worked great for the past couple years.

    Enter new requirements. I've created a custom XmlPackage called part.categorymenus.xml.config. I want to include it using the skin token syntax within the GlobalHeader file, like so:

    Code:
    (!XmlPackage name="part.categorymenus"!)
    But I get the following output to my page:

    Code:
      Home |  Products  (!XmlPackage name="part.categorymenus"!)  |  Services  |  Contact Us
    Rather than rendering the contents of the XmlPackage, the skin token is treated merely as regular text within the user control.

    Now, I think I have a clue as to why this happens. But I don't know how to solve it. User controls inherit from System.Web.UI.UserControl. In order for tokens to resolve, or interpret correctly by the aspdnsf parser, they must be part of a control or page that inherits AspDotNetStorefront.TemplateBase. But as far as I know, I cannot inherit from both...

    How can I use Skin Tokens within a User Control?

  2. #2
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    This is going to depend on when/how you load the control. For example, if you load the control directly in the template
    Code:
    <%@ Register TagPrefix="Custom" TagName="Control" Src="~/controls/CustomControl.ascx" %>
    ...
    ...
    ...
    <Custom:Control ID="cControl" runat="server" />
    and then in your control have something like this:

    .ascx
    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomControl.ascx.cs" Inherits="AspDotNetStorefront.Controls.CustomControl" %>
    (!XmlPackage Name="news.xml.config"!)
    .ascx.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace AspDotNetStorefront.Controls
    {
        public partial class CustomControl : System.Web.UI.UserControl 
        {
    
        }
    }
    the Parser will pick up on the token and render it appropriately. Now if you are loading it somewhere programmatically (eg. LoadControl("~/controls/CustomControl.ascx"); or by adding it to an .aspx webpage), then the Parser will have already fired and the token will render as plain text.

    The easiest thing to do would just be to create a simple custom control that can execute the xmlpackages and then use this control in all of your other custom controls any time you need an xmlpackage. First the XmlPackage custom control:

    .ascx
    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="XmlPackage.ascx.cs" Inherits="AspDotNetStorefront.Controls.XmlPackage" %>
    <asp:Literal ID="lit1" runat="server" Mode="PassThrough" />
    .ascx.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using AspDotNetStorefrontCore;
    
    namespace AspDotNetStorefront.Controls
    {
        public partial class XmlPackage : System.Web.UI.UserControl
        {
            public String Name { get; set; }
    
            protected override void OnLoad(EventArgs e)
            {
                SkinBase sb = Page as SkinBase;
    
                if (Name.Length != 0 && Name.Contains("xml.config"))
                {
                    lit1.Text = AppLogic.RunXmlPackage("news.xml.config", sb.GetParser, sb.ThisCustomer, sb.SkinID, String.Empty, String.Empty, true, true);
                }
                
                base.OnLoad(e);
            }
        }
    }
    And then, utilizing the above custom control:

    .ascx
    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomControl.ascx.cs" Inherits="AspDotNetStorefront.Controls.CustomControl" %>
    <%@ Register TagPrefix="Custom" TagName="XmlPackage" Src="~/controls/XmlPackage.ascx" %>
    
    <Custom:XmlPackage Name="news.xml.config" runat="server" />
    .ascx.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace AspDotNetStorefront.Controls
    {
        public partial class CustomControl : System.Web.UI.UserControl 
        {
            
        }
    }
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  3. #3
    aboyce is offline Junior Member
    Join Date
    Jun 2011
    Location
    Chicago, IL
    Posts
    6

    Default

    Hi, this was exactly what I was looking for. I followed your directions, and it's rendering as:

    (!XmlPackage Name="news.xml.config"!)

    my ascx file looks like this:

    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsLoader.ascx.cs" Inherits="AspDotNetStorefront.Controls.NewsLoader" %>
    (!XmlPackage Name="news.xml.config"!)
    and the cs file looks like this:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace AspDotNetStorefront.Controls
    {
    
        public partial class NewsLoader : System.Web.UI.UserControl
        {
     
        }
    }
    I want to output that exact xml package. Any ideas?

  4. #4
    AspDotNetStorefront Staff - Scott's Avatar
    AspDotNetStorefront Staff - Scott is offline Administrator
    Join Date
    Mar 2007
    Location
    Ashland, OR
    Posts
    2,390

    Default

    Are you on 9x? The skin token format has changed a bit. Instead of:

    Code:
    (!XmlPackage Name="news.xml.config"!)
    ...try:

    Code:
    <%$ Tokens:XMLPACKAGE news.xml.config%>
    You'll have to put that in something like an asp literal. Take a look at how we add tokens in the stock template.master file and you should see what I mean.

  5. #5
    aboyce is offline Junior Member
    Join Date
    Jun 2011
    Location
    Chicago, IL
    Posts
    6

    Default

    Thanks for the reply.

    I tried this:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsLoader.ascx.cs" Inherits="AspDotNetStorefront.Controls.NewsLoader" %>
    <asp:Literal ID="Literal1" runat="server" Text="<%$ Tokens:XMLPACKAGE news.xml.config%>" />

    and I'm getting nothing at all now... And I am running Multistore 9.1

  6. #6
    aboyce is offline Junior Member
    Join Date
    Jun 2011
    Location
    Chicago, IL
    Posts
    6

    Default

    figured it out, it's actually this:

    Code:
    <%$ Tokens:XMLPACKAGE,news.xml.config %>
    missed the comma...

  7. #7
    chese79 is offline Junior Member
    Join Date
    Jul 2010
    Posts
    18

    Default Similar issue with string resources upgrading from 8.0.1.2 to 8.0.1.4

    I am basically seeing the same symptoms with String Resources upgrading from 8.0.1.2 to 8.0.1.4. Has the string resource format changed at all?

  8. #8
    ROBB is offline Senior Member
    Join Date
    Jun 2011
    Location
    United States
    Posts
    107

    Default String Resources

    @chese79

    You may need to reload your string resources. Take a look at this aricle http://manual.aspdotnetstorefront.co...ource-mgr.aspx

    Note: Be careful not to inadvertently overwrite any existing modified strings.