如何在asp.net中实现嵌入式自定义标签? [英] How to achieve embedded custom tags in asp.net?

查看:106
本文介绍了如何在asp.net中实现嵌入式自定义标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了这个示例:

<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对象和DatePopupButton对象。

My assumption is that inside the RadDatePicker there is a DateInput object, Calendar Object and DatePopupButton object.

我想拥有自己的自定义控件,该控件允许访问内部对象,例如

I would like to have my own custom control that allows access to an inner object e.g.

    <jonno:textbox id="txt1" runat="server"><FieldConfig fieldName="Input1"/></jonno:textbox>

理想情况下,我不希望FieldConfig类成为可视类,但是可以。

Ideally I don't want the FieldConfig class to be a visual class but it's ok if it is.

如何实现?

推荐答案

嵌入式自定义标签是控件的属性。要启用在标记中设置它们,您需要使用以下属性装饰控件和属性:

The embedded custom tags are properties of your control. To enable setting them in markup, you need to decorate your control and properties with the following attributes:


  • 控件:ParseChilden,PersistChildren

  • 属性:PersistenceMode

我使用的控件示例执行类似的操作:

Example from a control I use that does something similar:

/// <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上查找属性,以准确了解它们的作用。上面应该做你需要做的事情。
在标记中,我可以简单地分配两个视图:

Look the attributes up on msdn to read up on what they do exactly. The above should do what you need it to do though. In markup I can then simply assign the two views:

<ctl:EditingView runat="server">
<DisplayView>
    blah blah
</DisplayView>
<EditView>
    blah blah edit
</EditView>
</ctl:EditingView>

唯一的区别是我的属性仍然是WebControls,并带有更多的子控件。不过,只要您正确设置属性就没关系。

THe only difference is that my properties are still WebControls and take more child controls. It shouldn´t matter though, as long as you set your attributes right.

Menno

这篇关于如何在asp.net中实现嵌入式自定义标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆