Custom elements in ASP.NET with custom child-elements

后端 未结 3 598
我寻月下人不归
我寻月下人不归 2021-01-31 11:53

I know that it is possible to define custom tags in ASP.NET with User Controls. But as far as I know you can only add attributes to these controls. I would like to be able to em

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 12:12

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    
    namespace ComponentDemo
    {
        [ParseChildren( true )]
        public class MyGraph : System.Web.UI.WebControls.WebControl
        {
            private List _colors;
    
            public MyGraph() : base() { ;}
    
            [PersistenceMode( PersistenceMode.InnerProperty )]
            public List Colors
            {
                get 
                {
                    if ( null == this._colors ) { this._colors = new List(); }
                    return _colors; 
                }
            }
        }
    
        public class Color
        {
            public Color() : base() { ;}
            public string Value { get; set; }
        }
    }
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ComponentDemo._Default" %>
    <%@ Register Assembly="ComponentDemo" Namespace="ComponentDemo" TagPrefix="my" %>
    
    
    
    
    
        
    
    
        

提交回复
热议问题