Access to a variable declared in aspx.cs, in aspx, or a variable declared on the ascx.cs ascx page

I was asked in an interview, the weather, on which we can access a publicly declared variable that was declared on the aspx.cs or ascx.cs page on the aspx or ascx page, respectively.

+6
source share
3 answers

Yes. As far as it is publicly declared at the page level , you can access it. for writing <%= Variable %> for calculations and <% variable %> for binding <%# variable %>

+4
source

Yes you can, on an aspx page you can do:

 <%=yourVariable%> 

If you defined a .cs file in your code as:

 public string yourVariable; 

If you want to use it in the span on an aspx page, then:

 <span> <%= yourVariable %> </span> 

You can see: Access to CodeBehind variables or C # variables, Methods on an ASPX page in ASP.Net

+7
source

in a similar case, anyone helps

in aspx file:

  <%= SessionLengthMinutes %> minute(s), <%=Session["name"] %> 

in aspx.cs:

 public int SessionLengthMinutes { get { return Session.Timeout; } } 

I declared it public, although it could not access the aspx.cs elements in the aspx file.

thanks

0
source

All Articles