在.aspx文件访问属性设置值 [英] Access property setting value in .aspx file

查看:218
本文介绍了在.aspx文件访问属性设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够访问我的类文件SomeClass.cs在Settings.settings文件中定义为这样一个属性的值:

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 = Properties.Settings.Default;
string myValue = property.someValue; 

不过,我想从我的Default.aspx页面访问属性值。
我曾尝试:

However, I would like to access property values from my Default.aspx page. I have tried:

<% 
    TestProject.Properties.Settings property = Properties.Settings.Default;
%>

它给右侧的属性说法错误:这个名字属性不会在目前的情况下存在

It gives an error on the right side for Properties saying: "The name properties does not exist in the current context."

是否有可能从一个.aspx文件访问属性的项目?
我能想到的唯一方法是创建一个类的.cs,只是读取属性的项目,并提供干将.aspx文件可以使用。

Is it possible to access property items from an .aspx file? The only alternative I can think of is to create a .cs class that just reads property items and provides getters the .aspx file could use.

推荐答案

这就是>。
您可以变通方法,像这样的东西在你的code-背后:

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;

...

和重新出现在你的aspx:

And back in your aspx:

<%= this.Test %>

但我建议你使用的web.config 存储设置的东西。

这篇关于在.aspx文件访问属性设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆