简体   繁体   中英

Get variable value from code behind and use in aspx page

Variable in.aspx.cs file

public string apmt_val { get; set; }

I want to use this in.aspx page as

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:

<%=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 %>" />

Your Solution

<%if (this.apmt_val == "Some Value") { %> //logic <%}%>

<%if (this.yourvar == "value") { %> //set the logic here <%}%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM