控件代码如下 using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel;namespace WebApplication2 { /// <summary> /// WebCustomControl1 的摘要说明。 /// </summary> [DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")] public class WebCustomControl1 : System.Web.UI.WebControls.WebControl { private string text;
[Bindable(true), Category("Appearance"), DefaultValue("")] public string Text { get { return text; } set { text = value; } } /// <summary> /// 将此控件呈现给指定的输出参数。 /// </summary> /// <param name="output"> 要写出到的 HTML 编写器 </param> protected override void Render(HtmlTextWriter output) {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;namespace WebApplication2
{
/// <summary>
/// WebCustomControl1 的摘要说明。
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
} set
{
text = value;
}
} /// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(this.text);
}
}
}
测试页面(.aspx)中的按钮事件如下
private void Button1_Click(object sender, System.EventArgs e)
{
mycontrol.Text="reset control";
}
private void Button2_Click(object sender, System.EventArgs e)
{
TextBox1.Text=mycontrol.Text;
}mycontrol 为自定义的控件点击button2后TextBox1的值为空为什么得不到点击button1时付给mycontrol.text的值