[英]Get variable value present in sub class from code behind and use in aspx page
** code from.aspx.cs file ** ** 来自.aspx.cs 文件的代码 **
namespace namespace1
{
public partial class name1 : System.Web.UI.Page
{
public string variable1;
protected void Page_Load(object sender, EventArgs e)
{
}
}
public class name2
{
public string variable2;
}
}
I want to use variable variable2 in.aspx page as我想使用变量 variable2 in.aspx 页面作为
if(<%#variable2%> == "Some Value"){
// Do something
}
else{
// Do something
}
Tried using尝试使用
But getting errors但是出现错误
The class name2 is floating. class name2 是浮动的。 If you have an instance of it class name1 you can define a property and use that variable.
如果您有它的实例 class name1,您可以定义一个属性并使用该变量。
namespace namespace1
{
public partial class name1 : System.Web.UI.Page
{
public string variable1;
private name2 _instance = null;
protected void Page_Load(object sender, EventArgs e)
{
_instance = new name2 ();
}
public string MyProperty {
get{return _instance.variable2;}
}
}
public class name2
{
public string variable2;
}
}
Then you can use it like this in your view <%= MyProperty%>然后你可以在你的视图中像这样使用它 <%= MyProperty%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.