简体   繁体   中英

How to add custom property to asp.net custom server control?

我已经创建了一个asp.net自定义控件,现在想从将使用该控件的页面中向其传递一些值。有什么办法可以将自己的属性添加到该控件中(例如Label控件具有Text属性) )?

It's a class. Add a public property to it.

Assuming ASP.NET 3.5+ just create properties

public string YourProperty {get; set;}

Would be declarative on the control

Adding a property to a custom control in asp.net is no different than adding a property on any class in C# (for instance).

public class Custom : Control
{
    public string Text { get; set; }
}

只需将其添加为公共财产,即可满足您的需求。

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