`
txf2004
  • 浏览: 6872378 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

自定义控件学习笔记(二)

阅读更多

自定义控件学习笔记(二)--增加属性

1。要点

1)使用访问器,和写类是一样的

2。控件代码

usingSystem;
usingSystem.Web.UI;

namespaceTestCustomControl
...{
publicclassAddAttribute:Control
...{
privatestringtext;

publicstringText
...{
get...{returntext;}
set...{text=value;}
}


protectedoverridevoidRender(HtmlTextWriterwriter)
...{
writer.WriteFullBeginTag(
"h1");

writer.Write(Text);

writer.WriteEndTag(
"h1");
}

}

}

3。引用代码

<%...@PageLanguage="C#"AutoEventWireup="true"CodeFile="AddAttribute.aspx.cs"Inherits="TestCustomControl_First_AddAttribute"%>
<%...@RegisterTagPrefix="Surance"Assembly="AddAtrribute"Namespace="TestCustomControl"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>无标题页</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<Surance:AddAttributeID="A1"runat="server"Text="Test,Surance"/>
</div>
</form>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics