Reputation: 923
I would like to now the best way to use constants in web forms for C# since im new to this, my constants are in a separate class and this is how i use them
using Student.Scripts.Constants;
namespace Student
{
public partial class masterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
testLabel.Text = Constant.APP_NAME;
}
}
}
this writes what ever is in my constant to this label and it displays correctly, what i wanna know is this the right way, do you have to use a label every time, and what if i want to use the constant on the HTML tag were i cant use a label, what then?
Upvotes: 0
Views: 1208
Reputation: 503
I would start practicing MVC with razor, so you won't have to take care of some of the complexity on client side and just use HTML tags to create your UX.
In case you need to have your constants on server side, you may have a static class to do so, like:
public static class Constants
{
public const string AppName = "MyApp";
public const string AppVersion = "0.0.0.1";
}
As it was said before:
Since your constants are strings, you can use them anywhere you can use a string.
That includes the Text property of all controls.
Upvotes: 0
Reputation: 498942
Since your constants are strings, you can use them anywhere you can use a string.
That includes the Text
property of all controls.
Upvotes: 2