Wednesday, August 18, 2010

How to build a resource manager for web control development in asp.net

public class ResourceManager
{
    #region Properties
 
    private static string assemblyName = string.Empty;
    public static string AssemblyName
    {
        get
        {
            if (string.IsNullOrEmpty(assemblyName))
                assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
            return assemblyName;
        }
    }
 
    #endregion
 
    #region Static Methods
 
    public static string GetResourcePath(string path, Type type, Page page)
    {
        path = string.Format("{0}.{1}", AssemblyName, path);
        return page.ClientScript.GetWebResourceUrl(type, path);
    }
    public static void RegisterResource(Page page, Type type, string path, 
        ResourceType resourceType, string domainName)
    {
        RegisterResource(page, type, path, resourceType, domainName, AssemblyName);
    }
    public static void RegisterResource(Page page, Type type, string path, 
        ResourceType resourceType, string domainName, string assemblyName)
    {
        path = string.Format("{0}.{1}", assemblyName, path);
        string location = page.ClientScript.GetWebResourceUrl(type, path);
        location = string.Concat(domainName, location.Remove(0, 1));
        switch (resourceType)
        {
            case ResourceType.JavaScript:
                page.ClientScript.RegisterClientScriptInclude(path, location);
                break;
            case ResourceType.StyleSheet:
                LiteralControl include = new LiteralControl(
                    String.Format("<link rel='stylesheet' text='text/css' href='{0}' />", 
                    location));
                ((HtmlHead)page.Header).Controls.Add(include);
                break;
        }
    }
 
    #endregion
}

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...