When you write a custom control, register it on the page, and try again on the page, you can see the effect normally. However, when you execute this page, an error is reported, Unknown Server tag, I checked it online and found it on the web. add a paragraph in config
Custom Controls
Code
Namespace puretest
{
[Toolboxdata ("<{0}: pager runat = Server> </{0}: pager>")]
Public class Pager: Control
{
Public int currentpage
{
Get; set;
}
Public int pagesize
{
Get; set;
}
Public int totalcount
{
Get; set;
}
// Hack: the URL condition for paging should be included here
Protected override void render (htmltextwriter writer)
{
Base. Render (writer );
// Var first = currentpage-5;
// Var end = currentpage + 5;
// Var totalpage = getpagecount ();
// If (first <1)
//{
// First = 1;
//}
// If (end> totalpage)
//{
// End = totalpage;
//}
// Var sb = new stringbuilder ();
// Sb. append ("<Div id = 'pager'> ");
// For (VAR I = first; I <end; I ++)
//{
// If (I = currentpage)
//{
// Sb. appendformat ("<strong> {0} </strong>", I );
//}
// Else
//{
// Sb. appendformat ("<a href0000'{0}.html '>{0} </a>", I );
//}
//}
// Sb. append ("</div> ");
// Writer. Write (sb. tostring ());
Writer. Write ("My first control ");
}
Private int getpagecount ()
{
Return pagesize = 0? 0: (totalcount + pagesize-1)/pagesize;
}
}
}
Page
Code
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "default. aspx. cs" inherits = "puretest. _ default" %>
<% @ Register tagprefix = "MC" namespace = "puretest" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Div style = 'height: 30px; '> </div>
<MC: pager runat = "server"> </MC: pager>
</Div>
</Form>
</Body>
</Html>
Web. config
Code
<Pages>
<Controls>
<Add tagprefix = "asp" namespace = "system. Web. UI" assembly = "system. Web. Extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
<Add tagprefix = "asp" namespace = "system. web. UI. webcontrols "assembly =" system. web. extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/>
<Add tagprefix = "MC" namespace = "puretest" assembly = "puretest"/>
</Controls>
</Pages>
Reference link:
Http://blog.sina.com.cn/s/blog_55e42da60100i1t6.html
Http://forums.asp.net/t/1337638.aspx