简体   繁体   中英

How to reference another objects property in aspx page

I have a class, which is not present in the code behind, I have declared a property, say "Name". Now I want to access this property "Name" in the aspx page.

I know we can do that by creating another property or a string variable or a hidden field in the code behind page and setting the "Name" properties value to it and accessing this new property/variable/ hidden field using <%= %> in the aspx page.

But I don't want to go by the above approach.

So is there any other way.

You could add a property on your code behind which will hold a reference to your class:

public SomeClass MyClass 
{
    get
    {
        // return an instance of SomeClass here
        return new SomeClass();
    }
}

and then in the aspx page you could access this property:

<%= MyClass.SomeProperty %>

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