asp.net传递变量从code后面的.aspx [英] asp.net pass variable from code behind to .aspx
问题描述
我想我失去了一些东西在这里,但我不能找到一种方法,从我的code通过一个简单的变量隐藏文件.aspx页。
I guess I'm missing something here, but I can't find a way to pass a simple variable from my code behind file to the .aspx page.
在code后面我有:
昏暗测试的String =测试
在我的aspx页面我尝试:<%=测试%GT;
and in my aspx page I try: <%=test %>
这使我有以下错误:错误2测试未声明。它可能无法访问由于其保护级别
我忘记了一些东西在这里?
Am I forgetting something here?
推荐答案
声明测试
作为一个属性(在类级别),而不是一个局部变量,然后参考它是您目前做您的标记(C ++)。
Declare test
as a property (at the class level) instead of a local variable, then refer to it as you currently do in your markup (aspx).
10 VB.NET(自动属性):
VB.NET 10 (automatic properties):
Protected Property test As String = "Test"
pre-VB.NET 10(自动性能不支持)
Pre-VB.NET 10 (no support for automatic properties)
Private _test As String
Protected Property Test As String
Get
Return _test
End Get
Set(value As String)
_test = value
End Set
End Property
有了财产,你应该直接在code-背后值分配给它。
With the property in place you should assign a value to it directly in your code-behind.
这篇关于asp.net传递变量从code后面的.aspx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!