从页面代码访问代码隐藏变量 [英] Accessing code-behind variables from page code
本文介绍了从页面代码访问代码隐藏变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下两页:
- 默认.aspx
- Default.aspx.cs
如何使用 <% %>
语法从 (Default.aspx) 中的嵌入代码访问代码隐藏文件 (Default.aspx.cs) 中的变量?>
How do I access variables in the code-behind file (Default.aspx.cs) from my embedded code in (Default.aspx) with the <% %>
syntax?
推荐答案
Any public
或 protected
(但not private
,页面"本身继承自代码隐藏 Page
类)类级成员可以通过这种方式访问.例如,如果您的代码隐藏类有一个属性:
Any public
or protected
(but not private
, the "page" itself inherits from the code-behind Page
class) class-level member can be accessed in this way. For example, if your code-behind class has a property:
protected string SomeValue { get; set; }
然后在你的 aspx 代码中你可以引用它:
Then in your aspx code you can refer to it:
<% =SomeValue %>
这篇关于从页面代码访问代码隐藏变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文