Localization and dynamic user controls(page lifecycle)
-
I've got a site with dynamically loaded user controls (.NET 1.1). These controls make use of the page UIculture to adjust their output. One of these dynamic controls is a dropdown that allows language(culture) selection. The problem is, by the time the IndexChanged event fires to change the page culture, it is possible that other dynamically loaded controls have already loaded and used the old page culture. From what I've read, mostly (.NET 2.0), it appears that manually getting the value of a dropdown from the form is required and override the InitializeCulture method (which doesn't exist in 1.1) The above approach is difficult if the control is dynamically loaded as the control ID may not always be the same. Ideas? Thanks in advance.
-
I've got a site with dynamically loaded user controls (.NET 1.1). These controls make use of the page UIculture to adjust their output. One of these dynamic controls is a dropdown that allows language(culture) selection. The problem is, by the time the IndexChanged event fires to change the page culture, it is possible that other dynamically loaded controls have already loaded and used the old page culture. From what I've read, mostly (.NET 2.0), it appears that manually getting the value of a dropdown from the form is required and override the InitializeCulture method (which doesn't exist in 1.1) The above approach is difficult if the control is dynamically loaded as the control ID may not always be the same. Ideas? Thanks in advance.
Actually, if the dynamic control uses the current culture info in the rendering phase which happens after the post data changed event (such as the SelectedIndexChanged event of the dropdownlist), then the updated culture still takes effect. One of the examples for such a control is the Calendar. If your dynamic control uses the current culture before the IndexChanged event occurs, you might need to reload control or the web page. In the ASP.NET 2.0, if you use the resource expression with localization, you then need to override the InitializeCulture method as you know to programmatically set the culture info for the current thread. The reason for this is that this method is called before the resource expression is populated, so it makes sure that the resource is loaded properly. If you set the culture info after the resource is loaded, it does not have any effect for the resource expression, but it might affect the code using the cultureinfo which runs after the changes.
-
I've got a site with dynamically loaded user controls (.NET 1.1). These controls make use of the page UIculture to adjust their output. One of these dynamic controls is a dropdown that allows language(culture) selection. The problem is, by the time the IndexChanged event fires to change the page culture, it is possible that other dynamically loaded controls have already loaded and used the old page culture. From what I've read, mostly (.NET 2.0), it appears that manually getting the value of a dropdown from the form is required and override the InitializeCulture method (which doesn't exist in 1.1) The above approach is difficult if the control is dynamically loaded as the control ID may not always be the same. Ideas? Thanks in advance.
Update: I've thought about it some more. I do have controls that do some culture specific initialization work that happens before the prerender stage. So doing the culture change in the IndexChanged event will cause problems. What I am trying now is basically the same method suggested in some 2.0 documentation I read. That is reading the Request.Form[ controlName ] value in the Init phase and setting it there. In order to get around the problem of controlName changing due to dynamically added controls, I plan to use the following at runtime when the control is added. Session["SelectLanguageControlID"] = ctrl.UniqueID; This way, I can pull the value of controlName out of the session and retrieve my new value from the form during the Init phase. I'm not sure I like the architechture of this design... but it seems to be the best I've got so far.
-
Update: I've thought about it some more. I do have controls that do some culture specific initialization work that happens before the prerender stage. So doing the culture change in the IndexChanged event will cause problems. What I am trying now is basically the same method suggested in some 2.0 documentation I read. That is reading the Request.Form[ controlName ] value in the Init phase and setting it there. In order to get around the problem of controlName changing due to dynamically added controls, I plan to use the following at runtime when the control is added. Session["SelectLanguageControlID"] = ctrl.UniqueID; This way, I can pull the value of controlName out of the session and retrieve my new value from the form during the Init phase. I'm not sure I like the architechture of this design... but it seems to be the best I've got so far.
The Session data is accessible to all the web pages within the user context, so if data is specific for a web page, IMHO you may think of a way to persist the control id in the web page scope, for example using the ViewState. However, the ViewState data is loaded after the Init phase, so you can manage to use the hidden field in the way you want.