0

I am working on an asp.net app in which there is a requirement of dynamically changing the text of labels (label controls) depending on our requirements. For example if my app has "Customers" as a label in all the pages. But if I want to display "Clients" instead of "Customers" in every page throughout my app as a label. I should be able to do that at runtime.

From where should I start? what steps should be taken to achieve this task?

1
  • 1
    Depending on your requirements, this is very similar to the needs of people who have to localize their applications for different languages - and it's certainly possible to create custom cultures - so maybe that's a route to investigate? Sep 22, 2015 at 9:47

3 Answers 3

2

Not sure if I understood the question correctly . You can have a key in your web.config storing the value "Customers" or maybe "Clients"

Now in the page load call a method which returns the value of the Key. Assign that to the label's text property.

So when you change it in the config .. you can change the value throughout application.

1

As you have asked for through out the application hence you should use that labels in a user control and then it should be added where ever it is required. So for the global changes in the page_load event of control you can change the label text. And top of that you can expose a public property to rename it form the parent where ever you added user control.

4
  • Its not about one or two labels .I have more than 30 pages .Each page has 5 to 50 fields and hence the same number of labels.i should be able to change each label of each page as i need.will it be possible with user control method as u told? Any other way?
    – Pwavel002
    Sep 22, 2015 at 9:56
  • Then you will have to make decision on the page's page load method , Sep 22, 2015 at 9:59
  • which will be a better way to save or store new values that i want to display?like in place of "FName","Mname","LName" i want to display "First","Middle","Last".Where should i keep the new values?database or any other way?
    – Pwavel002
    Sep 22, 2015 at 10:07
  • As it is the part of UI. So i would recommend you to keep them in to xml file and read it and use them. Reason being :1.You can change any time the values in xml and it will reflect of UI. 2. It can be well customized as per the requirement. for an example for US you can keep one file and for China another one, Sep 22, 2015 at 10:10
0

If you want to set label value as Client throughout the application then its better to use Application State i.e.,

Application["Name"] = "Client"; //Set Value to The Application Object
Label1.Text = Application["Name"].ToString();

You can learn more about Application state from here

You can create Application state in Global control and on each page load you can assign this application value to your respective labels. Suppose later you need to Change the name from "CLient" to something else then just changing in Global control you can do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.