正好,解决了另一个问题,顺便把源码发给你,仅为参考!public class Rendered : Control, IPostBackDataHandler, IPostBackEventHandler { private String text = "Please Enter the Name,Address and Phone!"; private string name; private string address; private string phone; private string[] temp = new string[3]; private ArrayList list = new ArrayList(); public ArrayList List { get { return list; } set { list = value; } }
public String Text { get { return text; } set { text = value; } }
2.继承自Control,有界面,大部分组件继承于此类
3.继承自Component,无界面,类似DataAdapter组件
4.继承自现有组件,比如说继承自TextBox,来增加一些功能
5.继承自祖宗类Object,如果继承自Object做出像样的组件,只有高手才能办得到初学就先玩玩继承自UserControl的吧
做成DLL
{
private String text = "Please Enter the Name,Address and Phone!";
private string name;
private string address;
private string phone; private string[] temp = new string[3];
private ArrayList list = new ArrayList(); public ArrayList List
{
get
{
return list;
}
set
{
list = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public event CheckEventHandler Check;
protected virtual void OnCheck(CheckEventArgs ce)
{
if (Check != null)
{
Check(this,ce);
}
}
public virtual bool LoadPostData(string postDataKey,
NameValueCollection values)
{
name = values[UniqueID + "_name"];
address = values[UniqueID + "_address"];
phone = values[UniqueID + "_phone"]; temp[0] = name;
temp[1] = address;
temp[2] = phone;
list.Add(temp); Page.RegisterRequiresRaiseEvent(this);
return false;
} public virtual void RaisePostDataChangedEvent()
{
}
public void RaisePostBackEvent(string eventArgument)
{
OnCheck(new CheckEventArgs());
}
protected override void Render(HtmlTextWriter output)
{
string strOut = "<table align=center runat=server>" +
"<p>" + Text + "</p>" +
"<tr><td><input type=text name=" + this.UniqueID + "_name" + "></td>" +
"<td><input type=text name=" + this.UniqueID + "_address" + "></td>" +
"<td><input type=text name=" + this.UniqueID + "_phone" + "></td>" +
"<td><input type=submit name=" + this.UniqueID + " value='Submit' runat=server></td>" +
"</tr>" +
"</table>" +
"<table align=center runat=server border=1>" +
"<tr><td>Name</td><td>Address</td><td>Phone</td></tr>";
for (int i = 0; i < List.Count; i++)
{
string[] tempStrs = (string[])List[i];
strOut += "<tr><td>" + tempStrs[0] + "</td><td>" + tempStrs[1] + "</td><td>" + tempStrs[2] + "</td></tr>";
}
strOut += "</table>";
output.Write(strOut);
}
} public class CheckEventArgs : EventArgs
{
public CheckEventArgs()
{
}
}
public delegate void CheckEventHandler(object sender, CheckEventArgs ce);
private void Page_Load(object sender, System.EventArgs e)
{
if (this.Session["list"] != null)
{
ArrayList tempList = (ArrayList)this.Session["list"];
for (int i = 0; i < tempList.Count; i++)
{
uc_Table.List.Add(tempList[i]);
}
}
}
private void uc_Table_Check(object sender, MyApplication.CheckEventArgs ce)
{
this.Session["list"] = uc_Table.List;
uc_Table.Text = "<h2> You can enter more ! </h2>";
}
{
protected override bool ProcessKeyEventArgs(ref Message m)
{
char s=(char)m.Wparam;
if(m.Msg==0x0102) // 0x0102 这个消息需要
{
if((s<'A')||(s>'D'))
return true;
}
return base.ProcessKeyEventArgs (ref m);
}
}比如这样, 没几行代码,编译出来就是个可以用的,只能输入ABCD的TextBox了.虽然可能没什么实际价值(做选择题????) 上面的代码是刚才临时敲的,不保证那几个方法名称没拼写错误,如果有错自己改改吧,大致是这样.