Question

I'm having a problem creating a new CompositeControl.

Currently I have a custom control that inherits from TextBox, the control DOES NOT have the Style property defined, but I can set the property in the page Markup and the style will be applied correctly.

I'm trying to create a CompositeControl with the same functionality as the custom control, everything works fine until I try to set the Style property on the control, in compile time this error is thrown: "The 'Style' property cannot be set declaratively", this keeps happening even if I declare the 'Style' property in the code for the CompositeControl (Even if I use the 'new' keyword).

I cannot understand why I get the error in one of the controls and not in the other one.

Any advice will be appreciated.

Thanks

Was it helpful?

Solution

I "solved" it!

I just don't have to define the Style property in the composite control I'm creating, if I let it that way I can add the Style to the control and access it in the code of the control.

e.g.

  <cc1:MyCompositeControl runat="server" Style="background-color:Red" />

and in the MyCompositeControl code I can access it like:

  foreach (string item in Style.Keys)
  {
     input.Style.Add(item, Style[item]);
  }

And set the style to the control I want it applied to (in this case, the input control).

I still cannot understand why I cannot set the Style property though, but the good thing is that I don't need to.

Thanks for your help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top