Access property setting value in .aspx file

后端 未结 2 629
时光说笑
时光说笑 2021-01-22 23:57

I am able to access the value of a property defined in the Settings.settings file in my class file SomeClass.cs as such:

TestProject.Properties.Settings property         


        
相关标签:
2条回答
  • 2021-01-23 00:06

    Thats because Settings class is defined as internal. You can workaround that with something like this on your code-behind:

    ...

    public string Test { get; set; }
    

    ...

    this.Test = WebApplication1.Properties.Settings.Default.Test;
    

    ...

    And back in your aspx:

    <%= this.Test %>
    

    But I suggest you to use web.config to store settings stuff.

    0 讨论(0)
  • 2021-01-23 00:15

    I ended up just making a class specifically for retrieving those property values:

    Example:

    public class TestProperties
    {
        public static string getValue1()
        {
            return Properties.Settings.Default.Value1;
        }
    
        public static string getValue2()
        {
            return Properties.Settings.Default.Value2;
        }
    }
    

    Then in the .aspx file I retrieve the values as such:

    Value1: <%= TestProperties.Value1() %><br>
    Value2: <%= TestProperties.Value2() %><br>
    

    If anyone knows of an easier way to do this I'd like to get some comments on it.

    0 讨论(0)
提交回复
热议问题