Accessing variable declared in aspx.cs in aspx or variable declared in ascx.cs ascx page
Asked Answered
H

3

7

I was asked a question in an interview, weather we can access a publically declared variable which is been declared in aspx.cs or ascx.cs page in aspx or ascx page respectively.

Handclap answered 13/12, 2012 at 4:26 Comment(1)
check following link : #7407461Manta
H
4

Yes, As far as it's Publicly declared at Page Level, you can access it . for writing <%= Variable %> for computation and <% variable %> for binding <%# variable %>

Howsoever answered 13/12, 2012 at 4:45 Comment(0)
D
7

Yes you can, In ASPX page you can do:

<%=yourVariable%>

If you have defined in your code behind file .cs file as:

public string yourVariable;

If you want to use it in a span in aspx page then:

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

You may see: Accessing CodeBehind Variables or C# Variables, Methods in ASPX Page in ASP.Net

Daedal answered 13/12, 2012 at 4:29 Comment(0)
H
4

Yes, As far as it's Publicly declared at Page Level, you can access it . for writing <%= Variable %> for computation and <% variable %> for binding <%# variable %>

Howsoever answered 13/12, 2012 at 4:45 Comment(0)
M
0

in similar case, anyone helps

in aspx file:

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

in aspx.cs :

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

i have declared it as public, even though it was unable to access the aspx.cs elements in aspx file.

thanks

Misreckon answered 19/8, 2015 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.