using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;namespace WebTextBox
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomTextBox runat=server></{0}:WebCustomTextBox>")]
public class WebCustomTextBox : WebControl,INamingContainer
{
public WebCustomTextBox()
{
this.Width = 20;
this.Height = 100;
} [Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
} private TextBox txt1;
private TextBox txt2;
private TextBox txtResult;
private Button btn;
private Label lab;
public override ControlCollection Controls
{
get
{
return base.Controls;
}
} protected override void RenderContents(HtmlTextWriter output)
{
output.RenderBeginTag(HtmlTextWriterTag.Table);
output.RenderBeginTag(HtmlTextWriterTag.Tr); output.RenderBeginTag(HtmlTextWriterTag.Td);
txt1.RenderBeginTag(output);
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write("+");
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
txt2.RenderBeginTag(output);
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write("=");
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
txtResult.RenderBeginTag(output);
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
btn.RenderBeginTag(output);
output.RenderEndTag(); output.RenderEndTag();
output.RenderEndTag(); base.RenderContents(output);
} protected override void CreateChildControls()
{
txt1 = new TextBox();
txt1.ID = "txt1";
txt1.Width = 50; txt2 = new TextBox();
txt2.ID = "txt2";
txt2.Width = 50; txtResult = new TextBox();
txtResult.ID = "txtResult";
txtResult.Width = 50; btn = new Button();
btn.ID = "btn";
btn.Width = 50;
btn.Text = "account";
btn.Click += new EventHandler(btn_Click); lab = new Label();
lab.Text = "请在文本框内输入数值类型";
lab.Visible = false; this.Controls.Add(txt1);
this.Controls.Add(txt2);
this.Controls.Add(txtResult);
this.Controls.Add(btn);
this.Controls.Add(lab);
} protected void btn_Click(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;namespace WebTextBox
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomTextBox runat=server></{0}:WebCustomTextBox>")]
public class WebCustomTextBox : WebControl,INamingContainer
{
public WebCustomTextBox()
{
this.Width = 20;
this.Height = 100;
} [Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
} private TextBox txt1;
private TextBox txt2;
private TextBox txtResult;
private Button btn;
private Label lab;
public override ControlCollection Controls
{
get
{
return base.Controls;
}
} protected override void RenderContents(HtmlTextWriter output)
{
output.RenderBeginTag(HtmlTextWriterTag.Table);
output.RenderBeginTag(HtmlTextWriterTag.Tr); output.RenderBeginTag(HtmlTextWriterTag.Td);
txt1.RenderBeginTag(output);
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write("+");
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
txt2.RenderBeginTag(output);
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write("=");
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
txtResult.RenderBeginTag(output);
output.RenderEndTag(); output.RenderBeginTag(HtmlTextWriterTag.Td);
btn.RenderBeginTag(output);
output.RenderEndTag(); output.RenderEndTag();
output.RenderEndTag(); base.RenderContents(output);
} protected override void CreateChildControls()
{
txt1 = new TextBox();
txt1.ID = "txt1";
txt1.Width = 50; txt2 = new TextBox();
txt2.ID = "txt2";
txt2.Width = 50; txtResult = new TextBox();
txtResult.ID = "txtResult";
txtResult.Width = 50; btn = new Button();
btn.ID = "btn";
btn.Width = 50;
btn.Text = "account";
btn.Click += new EventHandler(btn_Click); lab = new Label();
lab.Text = "请在文本框内输入数值类型";
lab.Visible = false; this.Controls.Add(txt1);
this.Controls.Add(txt2);
this.Controls.Add(txtResult);
this.Controls.Add(btn);
this.Controls.Add(lab);
} protected void btn_Click(object sender, EventArgs e)
{
}
}
}
解决方案 »
- 控件backcolor问题
- 很简单的问题,进来的都有分...
- 用户控件的大小问题,看起来简单,真一想头痛!!!!
- 有关datagrid排序的弱智问题哥哥姐姐们给个答案
- 来就有分! 暴强贴:从.NET平台调用Win32 API ,
- 请教,DataSet怎样保存到.txt文本文档?在线等候。。。。
- 高手帮忙!Dropdownlist使用AutoPostBack后,JavaScript菜单出问题了!!!!!
- 请问怎样在.net中的窗口中打开另一个窗口
- 使用asp.net后台更新焦点图(已实现)
- 急急,,Response.Write用法
- btn3控制主线程,btn1,btn2,分别控制子线程,请线程方面牛人帮忙解决下,小弟初学线程
- 请教一个C#获取数值的问题~!!
还是using 上没加啥东西?