我找到了这个例子:
<telerik:RadDatePicker
ID="RadDatePicker1"
runat="server">
<DateInput Width="100%"></DateInput>
<Calendar
CellAlign="Center"
CellVAlign="Middle"
DayNameFormat="FirstLetter"
FirstDayOfWeek="Default"
MonthLayout="Layout_7columns_x_6rows"
Orientation="RenderInRows"
TitleAlign="Center"
UseColumnHeadersAsSelectors="False"
ShowRowHeaders="False">
</Calendar>
<DatePopupButton
CssClass="radPopupImage_Default"
BorderColor="#D0E1F2"
BorderStyle="Solid"
BorderWidth="1px" />
我的假设是在RadDatePicker内部有一个DateInput对象,Calendar Object和DatePopupButton对象。
我想拥有自己的自定义控件,允许访问内部对象,例如
<jonno:textbox id="txt1" runat="server"><FieldConfig fieldName="Input1"/></jonno:textbox>
理想情况下,我不希望FieldConfig类成为可视类,但如果是,则可以。
我怎样才能做到这一点?
答案 0 :(得分:2)
嵌入式自定义标记是控件的属性。要在标记中设置它们,您需要使用以下属性修饰控件和属性:
我使用的控件的例子做了类似的事情:
/// <summary>
/// Control that will conditionally show one of two views
/// </summary>
[ParseChildren(true)]
[PersistChildren(true)]
public class EditingView : CompositeControl
{
#region private fields
private View _displayView = new View();
private View _editView = new View();
#endregion
#region properties
/// <summary>
/// The view that will be rendered in display mode
/// </summary>
[PersistenceMode(PersistenceMode.InnerProperty)]
public View DisplayView
{
get
{
return _displayView;
}
set
{
_displayView = value;
}
}
/// <summary>
/// The view that will be rendered in editing mode
/// </summary>
[PersistenceMode(PersistenceMode.InnerProperty)]
public View EditView
{
get
{
return _editView;
}
set
{
_editView = value;
}
}
/* Implementation details hidden */
}
查看msdn上的属性,了解他们的确切行为。以上应该做你需要它做的事情。 在标记中,我可以简单地分配两个视图:
<ctl:EditingView runat="server">
<DisplayView>
blah blah
</DisplayView>
<EditView>
blah blah edit
</EditView>
</ctl:EditingView>
唯一的区别是我的属性仍然是WebControls并采取更多的子控件。不过,只要你设置正确的属性就没关系了。
门诺