惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Schneier on Security
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
T
Threat Research - Cisco Blogs
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
The Last Watchdog
The Last Watchdog
Latest news
Latest news
AI
AI
Webroot Blog
Webroot Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Hacker News
The Hacker News
Google DeepMind News
Google DeepMind News
S
Securelist
IT之家
IT之家
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
博客园 - Franky
美团技术团队
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Security Archives - TechRepublic
Security Archives - TechRepublic
Security Latest
Security Latest
T
Tailwind CSS Blog
S
Security Affairs
S
Security @ Cisco Blogs
H
Heimdal Security Blog
腾讯CDC
N
News | PayPal Newsroom
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
博客园_首页
Jina AI
Jina AI
M
MIT News - Artificial intelligence
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
F
Full Disclosure
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
The Blog of Author Tim Ferriss
Schneier on Security
Schneier on Security
N
News and Events Feed by Topic
NISL@THU
NISL@THU
C
Cisco Blogs
T
Troy Hunt's Blog
O
OpenAI News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - kenly33

ORM及代码生成器和插件C#源码(最新版Kenly.DBFramework4.5.8.5) 處理RadioButtonList客戶端事件 - kenly33 - 博客园 对象关系映射架构(DBFramework)及代码生成器和插件(源码) 使對象支持自定義比較 統計分數 讀寫XML文檔 - kenly33 - 博客园 Visual Studio Team System简介 过滤某些字段重复的记录 MultiFileUploador GridViewNavigator Gridview梆定 兩個輸入框只允許一個輸入 Gridview中梆定得RadioButton Javascript 隱藏或顯示某區域 ASP.NET 2.0中合并 GridView 的表头单元格 鲸鱼哲学 Javascript彈出對話框 FxCop Rules Atlas使用演练
VS2005 RESOURCE MANAGEMENT
kenly33 · 2006-12-13 · via 博客园 - kenly33

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Aoumatically load all resources for server controls on target page .
/// </summary>
public static class TextResourceManager
{

    #region Public


    /// <summary>
    /// Gets string resource from resources file by control's ID and assigns the string to control's Value or Test property .
    /// </summary>
    /// <param name="control"></param>
    public static void LoadResource(System.Web.UI.Control control)
    {
        SetControlText(control, GetString(control.ID));
    }

    /// <summary>
    /// Aoumatically loads all resources for server controls on target page .
    /// </summary>
    /// <param name="targetPage"></param>
    public static void LoadResources(System.Web.UI.Page targetPage)
    {
        foreach (System.Web.UI.Control subControl in targetPage.Controls)
        {
            LoadResources(subControl);
        }
    }

    /// <summary>
    /// Aoumatically loads all resources for server controls on container control .
    /// </summary>
    /// <param name="containerControl"></param>
    public static void LoadResources(System.Web.UI.Control containerControl)
    {
        string resource = "";

        foreach (System.Web.UI.Control subControl in containerControl.Controls)
        {
            resource = GetString(subControl.ID);
            if (!string.IsNullOrEmpty(resource))
            {
                SetControlText(subControl, resource);
            }
            if (subControl.Controls.Count > 0)
            {
                LoadResources(subControl);
            }
        }

    }

 public static void LoadResources(GridView gridview)
    {
        string resource = "";

        foreach (DataControlField header in gridview.Columns)
        {
            resource = GetString(header.HeaderText);
            if (!string.IsNullOrEmpty(resource))
            {
                header.HeaderText = resource;
            }
        }

    /// <summary>
    /// Gets string resource from resources file by resource name .
    /// </summary>
    /// <param name="resourceName"></param>
    /// <returns></returns>
    public static string GetString(string resourceName)
    {
        string value = "";
        if (string.IsNullOrEmpty(resourceName))
        {
            return value;
        }

        try
        {
            SetCulture(Resources.Resource.Culture);
            value = Resources.Resource.ResourceManager.GetString(resourceName);
        }
        catch
        {
        }
        return value;
    }

    /// <summary>
    /// Setup current Thread's culture by culture name . such as "en-us" .
    /// </summary>
    /// <param name="cultureName"></param>
    public static void SetCulture(string cultureName)
    {
        try
        {
            Resources.Resource.Culture = new System.Globalization.CultureInfo(cultureName);
            System.Threading.Thread.CurrentThread.CurrentCulture = Resources.Resource.Culture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = Resources.Resource.Culture;
        }
        catch
        {
        }
    }

    /// <summary>
    /// Setup current Thread's culture .
    /// </summary>
    /// <param name="culture"></param>
    public static void SetCulture(System.Globalization.CultureInfo culture)
    {
        try
        {
            Resources.Resource.Culture = culture;
            System.Threading.Thread.CurrentThread.CurrentCulture = Resources.Resource.Culture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = Resources.Resource.Culture;
        }
        catch
        {
        }
    }


    #endregion


    #region Private

  
    /// <summary>
    ///
    /// </summary>
    /// <param name="control"></param>
    /// <param name="value"></param>
    private static void SetControlText(System.Web.UI.Control control, object value)
    {
        if (control == null || value==null)
        {
            return;
        }
        System.Reflection.PropertyInfo controlPropertyInfo = control.GetType().GetProperty("Value");
        if (controlPropertyInfo != null)
        {
            controlPropertyInfo.SetValue(control, value, null);
        }

        controlPropertyInfo = control.GetType().GetProperty("Text");
        if (controlPropertyInfo != null)
        {
            controlPropertyInfo.SetValue(control, value, null);
        }
    }


   #endregion
}