Click here to Skip to main content
15,917,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i globalize the server controls Text or dynamic data in asp.net?
Posted
Comments
Suvendu Shekhar Giri 28-Apr-15 2:03am    
Globalize meaning? Can you please explain a little more about your requirement?
Member 11644406 28-Apr-15 2:18am    
i have to convert a website to multilingual..i am able to convert the static text to the other language by using resource file but unable to convert the text in the buttons,labels,dropdowns etc..can u suggest me a method how to do this
Suvendu Shekhar Giri 28-Apr-15 2:28am    
My suggetsion is to keep those values too in the resource file.
Member 11644406 28-Apr-15 2:37am    
i have already placed that text and of the controls in Resource files but unable to bind them.
Suvendu Shekhar Giri 28-Apr-15 2:41am    
It should work. Can you please share the code, how you have assigned values to those controls?

1 solution

A quick example using OnPreRender, if you manually add the items yourself.
THere are several solutions to such a problem, but this is one of them.

THe control in the aspx/ascx file
ASP.NET
<asp:dropdownlist id="ddlExample" runat="server" onprerender="ddlExample_OnPreRender"></asp:dropdownlist>


The codebehind for the control/page:
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (false == Page.IsPostBack)
            {
                BindItems(ddlExample);
            }
        }

        const string FoodTemplate = "FoodTemplate";
        const string BeverageTemplate = "BeverageTemplate";

        private void BindItems(DropDownList ddlControl)
        {
            if (ddlControl == null)
                return;

            ddlControl.Items.Clear();
            ListItem liFood = new ListItem(FoodTemplate, "0");
            ListItem liBeverage = new ListItem(BeverageTemplate, "1");
            ddlControl.Items.Add(liFood);
            ddlControl.Items.Add(liBeverage);

        }

        protected void ddlExample_OnPreRender(object sender, EventArgs e)
        {
            if (sender is DropDownList)
            {
                DropDownList dl = (DropDownList)sender;
                foreach (ListItem listItem in dl.Items)
                {
                    switch (listItem.Text)
                    {
                        case FoodTemplate:
                            listItem.Text = WebApplication11.Properties.Resources.FoodTemplate;
                            break;
                        case BeverageTemplate:
                            listItem.Text = WebApplication11.Properties.Resources.BeverageTemplate;
                            break;
                    }                    
                }
            }
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900