日期:2014-05-20  浏览次数:20922 次

自定义控件的问题
如何在自定义控件里自定义一个属性,可以在PropertyGird中像TabContrl控件中的TabPages属性一样可以弹出一个Form来维护这个属性?谁能给个简单的代码实例?

------解决方案--------------------
WebUserControl.ascx:
<%@ Control Language= "C# " AutoEventWireup= "true " CodeFile= "WebUserControl.ascx.cs " Inherits= "WebUserControl " %>
<asp:Label ID= "Label1 " runat= "server " Text= "Label "> </asp:Label>
<asp:RadioButtonList ID= "RadioButtonList1 " runat= "server ">
</asp:RadioButtonList>
WebUserControl.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}
string strValue;
public string TextValue //自定義一個屬性
{
set { TextValue = value; }
get { return strValue; }
}
}
在aspx中加載這個控件,選擇屬性就可以看到了.
------解决方案--------------------
在属性前加
[Browsable(true)]
------解决方案--------------------
达到lz的要求所需步骤比较多,建议在msdn上search ControlDesigner 和 ControlBuilder 类的用法

------解决方案--------------------
把父类换掉,继承和tabpages同样的父类,把属性方法重写即可

我在WEB中遇到过同样的问题