[英]How to initialize my web control properties at design-time?
I need a way to initialize my web control's properties when it's dropped on the designer area. 当将Web控件放置在设计器区域时,我需要一种初始化其属性的方法。 As "initialize" I mean: If my control has a property Prop1.
作为“初始化”,我的意思是:如果我的控件具有属性Prop1。 I need to assign a value to Prop1 and I need this value to be persisted on ASPx.
我需要为Prop1分配一个值,并且需要将该值保留在ASPx上。
I tried the following: 我尝试了以下方法:
My question: How do I initialize my control properties? 我的问题:如何初始化控件属性?
PS: I know how to set my control's properties. PS:我知道如何设置控件的属性。 I use the following code that works fine on a smart-tag:
我使用以下在智能标记上正常运行的代码:
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.Component)["Prop1"];
descriptor.SetValue("Value");
Edit 编辑
I forgot to mention I cannot use ToolBoxData because I need to make processing to determine the value of the property 我忘了提到我不能使用ToolBoxData,因为我需要进行处理以确定该属性的值
[ToolboxData("<{0}:MyControl runat=\"server\" Prop1=\"Value\" />")]
public class MyControl
{
}
descriptor.SetValue("Value");
There is no such method. 没有这种方法。 MSDN I also don't really understand why are you using reflection to set the property of a known type?
MSDN我也不太了解您为什么要使用反射来设置已知类型的属性?
Maybe this can help you a bit: A Crash Course on ASP.NET Control Development: Design-Time Features and Capabilities 也许这可以对您有所帮助: ASP.NET控件开发速成班:设计时功能和功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.