http://dev.csdn.net/article/76585.shtm这篇文章写的我都明白,但是如果我把资源文件放在自己开发组件中那又该怎么办??
也就是说自定义组件如何获取调用它的程序的CurrentCulture和CurrentUICulture区域性信息?
(自定义组件可能在exe/asp.net中使用)
解决方案 »
- 关于Menu控件的问题
- 简单随机数算法请教
- href问题
- 流量统计
- asp.net里将table里面的数据导入到Excel模板里
- Button.Attributes.Add("onclick","javascript:deleteConfirm();") 问题终于搞定,献给和我一样困惑的兄弟!
- 通过Microsoft Visual Studio .NET创建web项目的错误;不能在预先设置好的虚拟目录中创建web项目
- 关于.dll文件
- 请问在ASP。NET里如何判断一个对象是否被创建?
- 如何在服务端获取客户端的ie临时目录并删除其中某个文件?
- 如何遍历DataList中模板列里的RadioButtonList?
- 怎样利用response.redirect()传递多个参数变量?
在组件中调用的话是组件线程的CurrentCulture/CurrentUICulture,而不是调用者的
CurrentCulture/CurrentUICulture例如:
调用者
System.Globalization.CultureInfo newCulture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = newCulture;Thread.CurrentThread.CurrentCulture
这里是"en-US"组件中:
Thread.CurrentThread.CurrentCulture ='zh-CN'.
我的机子是中文系统,区域设置为"zh-CN".我在asp.net中有以下代码:
System.Globalization.CultureInfo newCulture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = newCulture;
Response.Write(System.Thread.CurrentThread.CurrentCulture)
这里是"en-US"
然后载入我开发的组件.
在组件中:
string str=System.Thread.CurrentThread.CurrentCulture;
调试跟踪了一下,发现str="zh-CN",如果是您所说的那样的话,这里应该是str="en-US"..
{
System.Globalization.CultureInfo newCulture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = newCulture;
string str = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
...
if(CJH.Tools.CheckData.IsInteger(tbNumber.Text))
{
....
}
}
倒,我在申明一下..其实我也想到办法解决,就是把区域性信息放在某个其他的配置文件中,例如:web.config,或者其他的xml,ini,文本文件中也行,然后asp.net中和自己开发的组件中都去读取,不过我不想这样做,我想能不能直接在组件中获取到引用该组件的asp.net程序中设置的System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = newCulture;
string str = System.Threading.Thread.CurrentThread.CurrentCulture.Name;