var alinks_link; var trackImage = new Image(); function alinks_click(link) { var keyphrase = link.innerHTML; trackImage.src = 'http://www.thecredence.com/wp-content/plugins/alinks/classes/aLinksAjax.php?log=' + keyphrase; pause(1000); return true; } function pause(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) { now = new Date(); if (now.getTime() > exitTime) return; } }
You seem to be using a version of Internet Explorer.你似乎可以用一个版本的ie 。 For a safer browsing experience, please consider一个更安全的浏览体验,请考虑 and

If you're new here, you may want to subscribe to our RSS feed as well as to our NewsLetter (on Top Right hand menu) to get highly informative articles weekly...and NO, we never spam!如果你是新这里,你可以订阅我们的rss以及我们简讯 (顶右手菜单) ,以获得翔实周刊文章… …不,我们从来垃圾!

The job of each server-side control is to render a particular area of the asp page.工作每服务器端控制,是要将某一领域的asp页。 The page contains a list of such controls which were added by the coder and when the time to show the page to the user come every control in that list is called to render itself.网页载列了这些管制措施所增加的编码和时机成熟时,以显示页用户来控制每一个在这一名单叫做使自己。 The supported function of predefining the way controls render themselves give the coder to express a particular data in unlimited ways.辅助功能predefining方式控制,使自己给编码表达一个特定数据无限的方式。

How Custom DataBound Controls works如何定制databound控制工程

Every server-side control in ASP.NET derives from System.Web.UI.Control even the Page class.每个服务器端控制在asp.net来自system.web.ui.control连级页。 The Control class has a “Render” virtual function with a single parameter of type HtmlTextWriter which is responsible for how the control will be presented to user.对照班都有一个"渲染"虚拟功能单一参数型htmltextwriter是负责如何控制将提交给用户。

Practice Rendering Custom ontrols实践绘制风俗间歇

The best way to introduce the benefits of rendering custom controls is the practice method.最好引进好处绘制控件是实践方法。 Let’s assume we have the following table in SQL让我们假设我们有以下表在sql
2 - 1.png

The page we are going to create should show every user from the database who has article_result more than ‘0’.页面,我们会创造应该拿出每个用户都从数据库中的人已article_result超过'0 ' 。 So follow the next steps:所以跟随下一步骤:
1. 1 。 Create a simple Web site containing one default.aspx page.创建一个简单的网站,其中含default.aspx页面。
2. 2 。 Build the data table above or use another data source.建立数据表或使用另一个数据源。
3. 3 。 Create a new Web Control library.创造一个新的网络控制的图书馆。
2格式

4. 4 。 Declare in the control appropriate dataset.宣布在适当的控制数据。
5. 5 。 Override the RenderContents function.凌驾rendercontents功能。

   protected override void RenderContents ( HtmlTextWriter output ) { if ( !DesignMode ) { String s = "" ;                 s += ( @ " <table  >" ) ;                   s += ( @ " <tr>" ) ;                 foreach ( DataColumn c in UserDataSet. Columns ) { s += ( @ " <td border=" "2" " style=" "width: 130px;                     background-color:Silver" ">" ) ;                     s += c. ColumnName ;                     s += ( @ " <td/>" ) ; } s += ( @ " <tr/>" ) ;                 foreach ( DataRow dr in UserDataSet. Rows ) { s += ( @ " <tr>" ) ;                     foreach ( DataColumn c in dr. Table . Columns ) { s += ( @ " <td border=" "1" " style=" "width: 130px;                         background-color:WhiteSmoke" ">" ) ; if ( dr. Table . Columns . IndexOf ( c ) == 2 ) { for ( int i = 0 ; i < ( int ) dr [ c ] ; i++ ) { s += ( "X" ) ; } } else { s += dr [ c ] . ToString ( ) ; } s += ( @ " <td/>" ) ; } s += ( @ " <tr/>" ) ; }                   output. Write ( s ) ; } else { output. Write ( "Design mode, no data loaded!" ) ; } }  保护凌驾无效rendercontents  htmltextwriter输出 ,如果 ( ( !设计) (  ■ = " " ; ■ + =  @ " <table > "  ; ■ + =  @ " <tr> "  ; foreach  datacolumn 丙级 userdataset 。 栏目 ) ( ■ + =  @ " <td border=" "2" " style=" "width: 130px; background-color:silver" "> "  ; ■ + = c. columnname ; ■ + =  @ " <td/> "  ;  ■ + =  @ " <tr/> "  ; foreach  datarow dr  userdataset 。  ) ( ■ + =  @ " <tr> "  ; foreach  datacolumn 丙级博士。 栏目 ) ( ■ + =  @ " <td border=" "1" " style=" "width: 130px; background-color:whitesmoke" "> " ) ; 如果 博士专栏指数  == 2 ) (  int我= 0 ;我<  int 博士[] ;我+ ) ( ■ + =  " × "  ; ) ) 其他  ■ + =博士[]tostring ( ) ;  ■ + =  @ " <td/> "  ;  ■ + =  @ " <tr/> "  ; 输出。  ( ) ;  其他 输出。   "设计模式,没有数据加载! "  ; ) ) 

6. 6 。 Put the control in the default page and fill the dataset with data.把控制默认页和填补数据与资料。

   <% @ Page Language= "C#" AutoEventWireup= "true" CodeFile= "Default.aspx.cs" Inherits= "_Default" %> <% @ Register Assembly= "MyWebCustomControl" Namespace= "MyWebCustomControl" TagPrefix= "cc1" %>   <!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>Untitled Page</title> </head> <body> <form id= "form1" runat= "server" > <div style= "text-align: center" >         <cc1:webcustomcontrol1 id= "WebCustomControl1_1" runat= "server" height= "35px" width= "420px" ></cc1:webcustomcontrol1>     </div> </form>   </body> </html> protected void Page_Load ( object sender, EventArgs e ) { UserDataSetTableAdapters. GetUsersWithArticleResultTableAdapter da = new UserDataSetTableAdapters. GetUsersWithArticleResultTableAdapter ( ) ;   WebCustomControl1_1. UserDataSet = ( DataTable ) da. GetData ( ) ; }   <  @页语文= "# " autoeventwireup = "真实" codefile = " default.aspx.cs "继承= " _default " % > < % @大会登记= " mywebcustomcontrol "名字= " mywebcustomcontrol " tagprefix = " cc1 " % > < ! doctype html的市民 " -/ / w 3c的/ /拓展的x html1 .0过渡/ /恩 " , " < em>" > < html的xmlns = " http://www.w3.org/1999/xhtml " > <head runat= "server" > <title>无标题页< /标题> < /头> <body> <形式身分= " form1 " 5116 = "服务器" > <div style= "text-align: center" > <cc1:webcustomcontrol1 id= "webcustomcontrol1_1" runat= "server" height= "35px" width= "420px" > < / cc1 : webcustomcontrol1 > < /统治> < /表格> < /体> < / html的>保护无效page_load 对象发送电子eventargs ) ( userdatasettableadapters 。 getuserswitharticleresulttableadapter大=  userdatasettableadapters 。 getuserswitharticleresulttableadapter ( ) ; webcustomcontrol1_1 。 userdataset = 数据表大。 getdata ( ) ;  

And here is the result.这里是结果。

2 3.png

This reminds to a simple databound table except the third column, but in fact changing the code in RenderContents function makes data presentation very flexible.这提醒一个简单databound表除第三栏,但实际上改变了代码rendercontents功能,使数据呈现非常灵活。 Server controls gives the coder complete control over the generated html.服务器控制使编码完全控制生成的html 。 The given sample custom rendered control is not finished enough to be served to the end user.给样本习俗变得管制并不是完毕足以送达给最终用户。 Custom rendered controls usually manage a set of properties, fire events to their hosts, and render snapshots of themselves to their hosts.风俗使控制管理通常一套性能,火灾事件,其主机,并提供快照自己的主机。
The code above is not the best example for independence of browser version.在上述代码并不是最好的榜样独立的浏览器版本。 In ASP.NET 2.0 is added an adaptive rendering model, which inserts only those html tags and elements supported by the browser.在asp.net 2.0是一个补充自适应渲染模式,插入只有那些html标记和元素浏览器支持。

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet) (没有收视率却)
Loading ...  Loading ...装载...
Subscribe in a reader | 在订阅读者 |

Links you may find interesting -联系,你可以找到有趣- Yes !好的! Comments are FOLLOW So feel free to link back to related and meaningful posts.评论跟随感觉,所以无连接回相关和有意义的职位。

Post A Comment邮报评论