在 ASP.NET 中以编程方式设置用户控件的区域性
我想以编程方式设置用户控件的文化,它定义了几个标签、按钮和文本框...
通常,对于 aspx 页面,您覆盖 InitializeCulture-Method 并设置 Culture 和 UICulture 来实现此目的,唉 ASCX-Controls 这样做没有这个方法,那么我到底该怎么做呢?
我已经设置了本地资源 mycontrol.ascx.de-DE.resx、mycontrol.ascx.resx 和 mycontrol.ascx.en-GB.resx,但仅使用默认文件 (mycontrol.ascx.resx) 的值。
提前致谢。
丹尼斯
I'd like to programmatically set the culture of my User Control which defines several Labels, Buttons and Textboxes ...
Usually, for aspx-pages you override the InitializeCulture-Method and set Culture and UICulture to achieve this, alas ASCX-Controls do not have this Method, so how exactly would I do this?
I've set up the local resources mycontrol.ascx.de-DE.resx, mycontrol.ascx.resx and mycontrol.ascx.en-GB.resx but only the values of the default file (mycontrol.ascx.resx) are used.
Thanks in advance.
Dennis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当前区域性是线程范围的:
Page.Culture
和Page.UICulture
实际上设置了Thread.CurrentThread.CurrentCulture
和Thread.CurrentThread .CurrentUICulture
底层。如果用户控件是在页面标记中定义的,我认为您无能为力。如果使用
LoadControl()
加载它,您可以在调用之前暂时覆盖当前线程的区域性,并在调用之后恢复它,但这会很尴尬:The current culture is thread-wide:
Page.Culture
andPage.UICulture
actually setThread.CurrentThread.CurrentCulture
andThread.CurrentThread.CurrentUICulture
under the hood.If the user control is defined in your page markup, I don't think there's anything you can do. If you load it with
LoadControl()
, you can temporarily override the current thread's culture before the call and restore it afterward, but it would be quite awkward:我也花了几个小时来解决这个问题,终于得到了这个解决方案。
您只需重写
FrameworkInitialize()
而不是initilizeculture()
,例如:
只要将此代码放入您的ascx.cs文件中,则无需调用此覆盖函数。
I also spent hours on this problem and finally got This solution.
You only have to override the
FrameworkInitialize()
instead ofinitilizeculture()
,eg:
Jus Put this code inside your ascx.cs file, This override function does not need to be called.
我使用以下代码在项目页面中更改 asp.net mvc 的语言
,还在同一页面上使用了用户控件 (ascx)。当我使用操作链接更改语言时,视图页面语言已更改,但用户控件页面加载事件未捕获更改因此视图页面的语言发生了变化,但用户控件的语言没有改变
I used the following code to change the language for asp.net mvc in my project page
also I used usercontrol (ascx) on the same page.when I changed language with actionlink is changed viewpage language but user control pageload event isn't capture changing so viewpage's language changes but usercontrol's language doesn't change