不要再拖别人的控件----1.输出几个小东西
1.输出几个小东西
不要再拖别人的控件,开发自己的控件让别人拖去吧。
本博客文章如没有说明 都属于原创。
还有不懂的加.net 高级QQ群 86594082 咨询
namespace Mycontrol
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:checkEmail runat=server ></{0}:checkEmail>")]
public class checkEmail : WebControl
{
/// <summary>
/// 用视图存取值
/// </summary>
public string txtValue
{
get { return ViewState["txtvalue"] == null ? "" : ViewState["txtvalue"].ToString(); }
set { ViewState["txtvalue"] = value; }
}
protected override void RenderContents(HtmlTextWriter writer)
{
//输出一个表格 表格中有个文本框和按钮
writer.AddAttribute(HtmlTextWriterAttribute.Border, "1px #CCC red");
//输出表格
writer.RenderBeginTag(HtmlTextWriterTag.Table);
//输出tr
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
//输出td1
writer.RenderBeginTag(HtmlTextWriterTag.Td);
/*--------------------输出文本框----------------*/
writer.AddAttribute(HtmlTextWriterAttribute.Width, "100px");
writer.AddAttribute(HtmlTextWriterAttribute.Id, "txtEmailValue");
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
writer.AddAttribute(HtmlTextWriterAttribute.Value, this.txtValue);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
/*--------------------输出文本框 end----------------*/
//end 输出td1
writer.RenderEndTag();
//输出td2
writer.RenderBeginTag(HtmlTextWriterTag.Td);
/*--------------------输出按钮----------------*/
writer.AddAttribute(HtmlTextWriterAttribute.Width, "50px");
writer.AddAttribute(HtmlTextWriterAttribute.Id, "btnSend");
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "check");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
/*--------------------输出按钮 end---------------*/
writer.RenderEndTag();
//end 输出td2
writer.RenderEndTag();
//end 输出tr
writer.RenderEndTag();
//end 输出表格
writer.RenderEndTag();
}
}
}