如何在asp.net中实现嵌入自定义标签?

发布于 2024-12-05 21:03:48 字数 951 浏览 0 评论 0原文

我找到了这个例子:

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

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

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

理想情况下,我不希望 FieldConfig 类成为可视类,但如果是的话也没关系。

我怎样才能实现这个目标?

I found this example:

<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" />

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>

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

How can I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2024-12-12 21:03:48

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

  • 控件:ParseChilden、PersistChildren
  • 属性:PersistenceMode

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

/// <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>

唯一的区别是我的属性仍然是 WebControl,并带有更多子控件。不过,只要你正确设置你的属性,这就不重要了。

门诺

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:

  • Control: ParseChilden, PersistChildren
  • Properties: 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 */
}

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>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文