开发者

How to initialize my web control properties at design-time?

开发者 https://www.devze.com 2022-12-10 02:34 出处:网络
I need a way to initialize my web control\'s properties when it\'s dropped on the designer area. As \"initialize\" I mean: If my control has a property Prop1. I need to assign a value to Prop1 and I n

I need a way to initialize my web control's properties when it's dropped on the designer area. As "initialize" I mean: If my control has a property Prop1. I need to assign a value to Prop1 and I need this value to be persisted on ASPx.

I tried the following:

  1. Implement InitializeNewComponent on my ControlDesigner: This method is never called. It seems a bug.
  2. Implement Initialize on my ControlDesigner: This method is called, but somehow Visual Studio does not allow me to change control's property at this stage.
  3. Create a handler to IComponentChangeService.ComponentAdded (that was supposed to be called every time any control is created). This handler is never called.

My question: How do I initialize my control properties?

PS: I know how to set my control's properties. I use the following code that works fine on a smart-tag:

PropertyDescriptor descriptor = TypeDescri开发者_StackOverflowptor.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("<{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?

Maybe this can help you a bit: A Crash Course on ASP.NET Control Development: Design-Time Features and Capabilities

0

精彩评论

暂无评论...
验证码 换一张
取 消