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:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...