[英]Get variable value from code behind and use in aspx page
Variable in.aspx.cs file .aspx.cs 文件中的变量
public string apmt_val { get; set; }
I want to use this in.aspx page as我想将此 in.aspx 页面用作
if(<%#apmt_val%> == "Some Value"){
// Do something
}
else{
// Do something
}
field must be declared public or protected必须将字段声明为公共或受保护的
Then, to call it on the ASPX side:然后,在 ASPX 端调用它:
<%=apmt_val %>
<%=apmt_val %>
Note that this won't work if you place it on a server tag attribute.请注意,如果将其放在服务器标记属性上,这将不起作用。 For example:
例如:
<asp:Label runat="server" Text="<%=apmt_val %>" />
<asp:Label runat="server" Text="<%=apmt_val %>" />
Your Solution您的解决方案
<%if (this.apmt_val == "Some Value") { %> //logic <%}%>
<%if (this.apmt_val == "Some Value") { %> //逻辑 <%}%>
<%if (this.yourvar == "value") { %> //set the logic here <%}%> <%if (this.yourvar == "value") { %> //这里设置逻辑 <%}%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.