SlideShare a Scribd company logo
1 of 21
Chương 8

 Tùy biến điều khiển
   trong ASP.NET
Mục đích
   Xác định cần thiết của việc tạo custom
    controls
   Tạo điều khiển đơn giảng dùng
    ASP.NET

   Tạo Composite control dùng C#
   Sử dụng sự kiện với custom controls
                                Exploring ASP.NET / Session 15/ 2 of 22
Controls
   Các lớp được xây dựng cho việc tái sử dụng mã
     cần thiết tái sử dụng lại các điều khiển giao
    diện người dùng
   Control giúp tái sử dụng một cách trực quan
    cũng như bổ sung các chức năng tương ứng
   Giúp đóng gói các khả năng và phân phối
   ASP.NET controls dùng cho Web để tạo HTML
    hoặc WML, hiển thị trên trình duyệt người dùng



                                         Exploring ASP.NET / Session 15/ 3 of 22
Controls …
                                    A ssfffghfio i
                  Assfffg hfioi
                                    J hjkhjkhjkhj
                  J hjkhjkhj khj
                                    Uy uuiyu iy ui
                  Uy uu iy uiyu i
                                     ghg hghjgg g
                   g hghg hjg gg

        Code for a datagrid           Code for a dataview
 A ssfffghfioi
 Jhjkhjkhjkhj
 Uyuu iyuiyui
  ghghghjggg

   Code for a Label
Assfffghfioi
                                                     A ssfffghfioi
Jhjkhjkhjkhj
                                                     Jhj khjkhjkhj
Uyuu iyuiyui
                                                     Uyu uiyu iyu i
 ghghghjggg

Code for a radiobutton
                                                      g hg hghj ggg

 A ssfffghfioi
 Jhjkhjkhjkhj
                                             Code for a textbox
 Uyuu iyuiyui
  ghghghjggg

 Code for a checkbox
Assfffghfioi
Jhjkhjkhjkhj
Uyuu iyuiyui
 ghghghjggg

 Code for a button
                                                                      Exploring ASP.NET / Session 15/ 4 of 22
Custom Controls
       Tạo theo 2 cách




                         C#
 ASP.NET like Page
   Pagelets


                          Exploring ASP.NET / Session 15/ 5 of 22
Custom Control sử dụng
    Label Control
   MyLabel.ascx
<% @Control Language="C#" Debug="True" %>
<ASP:Label id="lblOne" runat="server" style="color:Red;
font-family: arial; font-size=40pt"></asp:Label>
<script language="C#" runat="server">
public string MyText
{
       get
   {
       // Do Nothing
              return(lblOne.Text);
   }
       set
       {
       lblOne.Text = value;
       }
                                              Exploring ASP.NET / Session 15/ 6 of 22
Custom Control dùng Label
      Control
 }
 </script>
 Label.aspx
<% @Register Tagprefix="MyFirstControl" TagName="MyLbl"
Src="MyLabel.ascx" %>

<MyFirstControl:MyLbl runat="Server" id ="AllMine"
MyText="My first custom control !!!" />




                                               Exploring ASP.NET / Session 15/ 7 of 22
Custom Controls dùng C#
Điều khiển này được viết hoàn toàn dùng C# mà không cần dùng bất cứ điều
khiển ASP.Net nào
 Repeater.cs

using System;
using System.Web;
using System.Web.UI;
namespace MyOwnControls
{
       public class TextRepeater : Control
   {
       protected override void Render(HtmlTextWriter writer)
       {
              int intCount;



                                                            Exploring ASP.NET / Session 15/ 8 of 22
Custom Controls dùng C#
    for (intCount=1; intCount<=3; intCount++)
    {
        writer.Write ("<h1>This is a custom control</h1>
<br>");
      }
    }
  }
}

Mã được lưu trong tập tin cs và được biên dịch thành dll và nên được đặt vào trong
thư mục bin của ứng dụng


csc /t:library / r:System.dll,System.Web.Dll Repeater.cs



                                                              Exploring ASP.NET / Session 15/ 9 of 22
Custom Controls dùng C#
Sử dụng trong rang ASP.Net

<% @Register TagPrefix="Mine" Namespace="MyOwnControls"
Assembly="Repeater" %>
<html>
<title>Custom control using C#</title>
       <body>
              <Mine:TextRepeater runat="server" />
       </body>
</html>




                                               Exploring ASP.NET / Session 15/ 10 of 22
Thuộc tính của Custom Controls
    Đế cho phép sử dụng tốt hơn các control, chúng ta có thể tạo thuộc
     tính cho các điều khiển
    Các thuộc tính này có thể thay đổi một cách tự động




 NewRepeater. cs
using System;
using System.Web;
using System.Web.UI;
namespace MyOwnControls
{
       public class TextRepeater : Control
       {
              public int timesToRepeat;
                                                       Exploring ASP.NET / Session 15/ 11 of 22
Properties of Custom Controls
public string myText;
public int TimesToRepeat
{
     get
     {
        return timesToRepeat;
     }
     set
     {
          if (timesToRepeat > 10)
              throw new ArgumentException ("The text should
not be repeated more than 10 times");
          else
               timesToRepeat = value;
       }
  }
                                               Exploring ASP.NET / Session 15/ 12 of 22
Properties of Custom Controls
public string MyText
 {
        get
        {
             return myText;
        }
        set
        {
             if (myText.Length > 25)
                throw new ArgumentException("The text
should not be more than 25 characters");
             else
                myText = value;
          }
 }


                                              Exploring ASP.NET / Session 15/ 13 of 22
Properties of Custom Controls
 protected override void Render(HtmlTextWriter writer)
 {
         for (int Count = 1; Count <= TimesToRepeat; Count++)
         {
            writer.Write("<h1>" + MyText + "</h1><br>");
         }
     }
 }
}




                                                   Exploring ASP.NET / Session 15/ 14 of 22
Composite Controls
   Các control đơn giản có thể kết hợp với nhau để
    tạo các control phức tạp  Composite
    controls.
   Composite controls có thể bao hàm các custom
    controls, cũng như các control của windows
   Mỗi trang asp.net bao gồm ít nhất một control 
    là mộtcomposite control




                                       Exploring ASP.NET / Session 15/ 15 of 22
Composite Controls – Ví dụ
  Composite.c
  s
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyOwnControls
{
  public class MyComposition : Control, INamingContainer
  {
       public int Val
       {
          get
          {
              this.EnsureChildControls();
              return Int32.Parse (((TextBox) Controls[1]).
Text);           }
                                              Exploring ASP.NET / Session 15/ 16 of 22
Composite Controls - Ví dụ
          set
          {
              this.EnsureChildControls();
              ((TextBox)Controls[1]).Text = value.ToString();
          }
        }
        protected override void CreateChildControls()
        {
           this.Controls.Add(new LiteralControl("<h3>Value: "));
           TextBox box = new TextBox();
           box.Text = "0";
           this.Controls.Add(box);
           this.Controls.Add(new LiteralControl("</h3>"));
        }
    }
}
                                                   Exploring ASP.NET / Session 15/ 17 of 22
Composite Controls – Ví dụ
composite control được tạo và sử dụng giống như các control khác trong asp.net

   Composite.asp
   x
<% @Register TagPrefix="MyOwnControls"
Namespace="MyOwnControls" Assembly="Composite" %>
<HTML>
    <title>Composite Controls</title>
      <script language="C#" runat="server">
      private void AddBtn_Click(Object sender, EventArgs e)
      {
         MyComposition1.Val = MyComposition1.Val + 1;
      }
      private void SubtractBtn_Click(Object sender, EventArgs
e)

                                                             Exploring ASP.NET / Session 15/ 18 of 22
Composite Controls – Ví dụ
  {
       MyComposition1.Val = MyComposition1.Val - 1;
     }
   </script>
   <body>
     <form method="post" action="ThisPage.aspx" runat=
"server" ID="Form1">
     <MyOwnControls:MyComposition id="MyComposition1"
runat="server" />
     <asp:button text="Add" OnClick="AddBtn_Click"
runat="server" ID="btnAdd" />
     <asp:button text="Subtract" OnClick="SubtractBtn_
Click" runat="server" ID="btnSubtract" />
     </form>
    </body>
</HTML>
                                              Exploring ASP.NET / Session 15/ 19 of 22
Composite Controls – Ví dụ




                      Exploring ASP.NET / Session 15/ 20 of 22
Summary
   Controls giúp tái sử dụng mã cũng như chức năng của nó
   Custom web controls được tạo theo 2 cách:
      Pagelets

      Web Controls dùng C#

   Pagelets là custom control nhưng giống một trang asp, và
    có phần mở rộng là .ascx.
   Web Controls render HTML tụ động.
   Custom Controls là kết hợp của các control khác
   Giao diện System.Web.UI.INamingContainer không
    có phương thức, ASP.Net dùng để tạo các unique ID.


                                              Exploring ASP.NET / Session 15/ 21 of 22

More Related Content

Viewers also liked

兒童前期親職教育
兒童前期親職教育兒童前期親職教育
兒童前期親職教育Kuo-Yi Chen
 
The Gifted Gazette
The Gifted GazetteThe Gifted Gazette
The Gifted Gazettefloridazandy
 
Group 1 case 1
Group 1 case 1Group 1 case 1
Group 1 case 1cookj111
 
Citizen Science: Association of American Medical Colleges
Citizen Science: Association of American Medical CollegesCitizen Science: Association of American Medical Colleges
Citizen Science: Association of American Medical CollegesDarlene Cavalier
 
4 agile developement_using_ccrc-sujeet_mishra
4 agile developement_using_ccrc-sujeet_mishra4 agile developement_using_ccrc-sujeet_mishra
4 agile developement_using_ccrc-sujeet_mishraIBM
 
Profession
ProfessionProfession
Professionpmizuo
 
Japanese Business Presentation
Japanese Business PresentationJapanese Business Presentation
Japanese Business PresentationTimk86k
 
200901011455420 申請連任簡報
200901011455420 申請連任簡報200901011455420 申請連任簡報
200901011455420 申請連任簡報Kuo-Yi Chen
 
Electrospn 17 yalcinkaya-full
Electrospn 17 yalcinkaya-fullElectrospn 17 yalcinkaya-full
Electrospn 17 yalcinkaya-fullmiroli
 
4.1.phat trien ct ham-thutuc-tktt
4.1.phat trien ct ham-thutuc-tktt4.1.phat trien ct ham-thutuc-tktt
4.1.phat trien ct ham-thutuc-tkttGiang Nguyễn
 
Team Dustin Wentzel
Team Dustin WentzelTeam Dustin Wentzel
Team Dustin WentzelAnnie Welbie
 
опрокидывающиеся сковороды Rus
опрокидывающиеся сковороды Rusопрокидывающиеся сковороды Rus
опрокидывающиеся сковороды RusSokirianskiy&Lazerson School
 

Viewers also liked (20)

Facebook101
Facebook101Facebook101
Facebook101
 
兒童前期親職教育
兒童前期親職教育兒童前期親職教育
兒童前期親職教育
 
10самса с картофелем
10самса с картофелем10самса с картофелем
10самса с картофелем
 
The Gifted Gazette
The Gifted GazetteThe Gifted Gazette
The Gifted Gazette
 
Animation
AnimationAnimation
Animation
 
Group 1 case 1
Group 1 case 1Group 1 case 1
Group 1 case 1
 
Citizen Science: Association of American Medical Colleges
Citizen Science: Association of American Medical CollegesCitizen Science: Association of American Medical Colleges
Citizen Science: Association of American Medical Colleges
 
4 agile developement_using_ccrc-sujeet_mishra
4 agile developement_using_ccrc-sujeet_mishra4 agile developement_using_ccrc-sujeet_mishra
4 agile developement_using_ccrc-sujeet_mishra
 
Ung dung web chuong 6
Ung dung web  chuong 6Ung dung web  chuong 6
Ung dung web chuong 6
 
Profession
ProfessionProfession
Profession
 
Japanese Business Presentation
Japanese Business PresentationJapanese Business Presentation
Japanese Business Presentation
 
200901011455420 申請連任簡報
200901011455420 申請連任簡報200901011455420 申請連任簡報
200901011455420 申請連任簡報
 
RSI - Railway Interchange 2011 Trade Show Prospectus
RSI - Railway Interchange 2011 Trade Show ProspectusRSI - Railway Interchange 2011 Trade Show Prospectus
RSI - Railway Interchange 2011 Trade Show Prospectus
 
Fiatomoram-pamokarana fitoloha
Fiatomoram-pamokarana fitolohaFiatomoram-pamokarana fitoloha
Fiatomoram-pamokarana fitoloha
 
Electrospn 17 yalcinkaya-full
Electrospn 17 yalcinkaya-fullElectrospn 17 yalcinkaya-full
Electrospn 17 yalcinkaya-full
 
4.1.phat trien ct ham-thutuc-tktt
4.1.phat trien ct ham-thutuc-tktt4.1.phat trien ct ham-thutuc-tktt
4.1.phat trien ct ham-thutuc-tktt
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
46fotosdanationalgeographic
46fotosdanationalgeographic46fotosdanationalgeographic
46fotosdanationalgeographic
 
Team Dustin Wentzel
Team Dustin WentzelTeam Dustin Wentzel
Team Dustin Wentzel
 
опрокидывающиеся сковороды Rus
опрокидывающиеся сковороды Rusопрокидывающиеся сковороды Rus
опрокидывающиеся сковороды Rus
 

Similar to Ung dung web chuong 8

Giao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharpGiao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharpngohanty13
 
Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...
Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...
Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...MasterCode.vn
 
Asp.net mvc 3 (c#) (9 tutorials) egroups vn
Asp.net mvc 3 (c#) (9 tutorials)   egroups vnAsp.net mvc 3 (c#) (9 tutorials)   egroups vn
Asp.net mvc 3 (c#) (9 tutorials) egroups vnNguyen Van Hung
 
Ajax control toolkit
Ajax control toolkitAjax control toolkit
Ajax control toolkitNguyen Huy
 
Bai tap java_script-html-2016
Bai tap java_script-html-2016Bai tap java_script-html-2016
Bai tap java_script-html-2016viethoang89
 
4.thuc thi menh lenh voi co so du lieu
4.thuc thi menh lenh voi co so du lieu4.thuc thi menh lenh voi co so du lieu
4.thuc thi menh lenh voi co so du lieuDao Uit
 
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...anh hieu
 
Net06 asp.net applications & state management
Net06 asp.net applications & state managementNet06 asp.net applications & state management
Net06 asp.net applications & state managementhoangnguyentien
 

Similar to Ung dung web chuong 8 (20)

Giao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharpGiao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharp
 
Asp control
Asp controlAsp control
Asp control
 
Ajax Control ToolKit
Ajax Control ToolKitAjax Control ToolKit
Ajax Control ToolKit
 
Ung dung web chuong 5
Ung dung web  chuong 5Ung dung web  chuong 5
Ung dung web chuong 5
 
Lap trinh asp.net
Lap trinh asp.netLap trinh asp.net
Lap trinh asp.net
 
Asp.net003
Asp.net003Asp.net003
Asp.net003
 
Asp
AspAsp
Asp
 
Unit Test
Unit TestUnit Test
Unit Test
 
Ung dung web chuong 4
Ung dung web  chuong 4Ung dung web  chuong 4
Ung dung web chuong 4
 
Aspnet 3.5 _05
Aspnet 3.5 _05Aspnet 3.5 _05
Aspnet 3.5 _05
 
Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...
Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...
Bài 2: Hướng dẫn làm việc với các điều khiển - Giáo trình FPT - Có ví dụ kèm ...
 
Asp.net mvc 3 (c#) (9 tutorials) egroups vn
Asp.net mvc 3 (c#) (9 tutorials)   egroups vnAsp.net mvc 3 (c#) (9 tutorials)   egroups vn
Asp.net mvc 3 (c#) (9 tutorials) egroups vn
 
Ajax control toolkit
Ajax control toolkitAjax control toolkit
Ajax control toolkit
 
Bai tap java_script-html-2016
Bai tap java_script-html-2016Bai tap java_script-html-2016
Bai tap java_script-html-2016
 
4.thuc thi menh lenh voi co so du lieu
4.thuc thi menh lenh voi co so du lieu4.thuc thi menh lenh voi co so du lieu
4.thuc thi menh lenh voi co so du lieu
 
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
 
400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2
400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2
400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2
 
Net06 asp.net applications & state management
Net06 asp.net applications & state managementNet06 asp.net applications & state management
Net06 asp.net applications & state management
 
Ung dung web chuong 7
Ung dung web  chuong 7Ung dung web  chuong 7
Ung dung web chuong 7
 
Asp.net 3.5 _1
Asp.net 3.5 _1Asp.net 3.5 _1
Asp.net 3.5 _1
 

More from Giang Nguyễn

Php can ban_bai1_laptrinhwebphp.com
Php can ban_bai1_laptrinhwebphp.comPhp can ban_bai1_laptrinhwebphp.com
Php can ban_bai1_laptrinhwebphp.comGiang Nguyễn
 
Lap trinh web dong voi php my sql
Lap trinh web dong voi php my sqlLap trinh web dong voi php my sql
Lap trinh web dong voi php my sqlGiang Nguyễn
 
Kentcources 110109221507-phpapp01
Kentcources 110109221507-phpapp01Kentcources 110109221507-phpapp01
Kentcources 110109221507-phpapp01Giang Nguyễn
 
Hay php architect eav modeling
Hay php architect   eav modelingHay php architect   eav modeling
Hay php architect eav modelingGiang Nguyễn
 
Haiphongit.com.tai lieu-php.my sql-thiet-ke-web-dong
Haiphongit.com.tai lieu-php.my sql-thiet-ke-web-dongHaiphongit.com.tai lieu-php.my sql-thiet-ke-web-dong
Haiphongit.com.tai lieu-php.my sql-thiet-ke-web-dongGiang Nguyễn
 
Haiphongit.com.tai lieu-laptrinh ph-pvamysql
Haiphongit.com.tai lieu-laptrinh ph-pvamysqlHaiphongit.com.tai lieu-laptrinh ph-pvamysql
Haiphongit.com.tai lieu-laptrinh ph-pvamysqlGiang Nguyễn
 
Haiphongit.com.tai lieu-learning-php-my sql
Haiphongit.com.tai lieu-learning-php-my sqlHaiphongit.com.tai lieu-learning-php-my sql
Haiphongit.com.tai lieu-learning-php-my sqlGiang Nguyễn
 
Joomla administratormanual vi_20060206
Joomla administratormanual vi_20060206Joomla administratormanual vi_20060206
Joomla administratormanual vi_20060206Giang Nguyễn
 
Canbanvethietkevalaptrinhgame
CanbanvethietkevalaptrinhgameCanbanvethietkevalaptrinhgame
CanbanvethietkevalaptrinhgameGiang Nguyễn
 
Building websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menu
Building websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menuBuilding websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menu
Building websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menuGiang Nguyễn
 
Eclipse pdt indigo release review
Eclipse pdt   indigo release reviewEclipse pdt   indigo release review
Eclipse pdt indigo release reviewGiang Nguyễn
 
Bai tap lap trinh web voi joomla csau
Bai tap   lap trinh web voi joomla csauBai tap   lap trinh web voi joomla csau
Bai tap lap trinh web voi joomla csauGiang Nguyễn
 

More from Giang Nguyễn (20)

Php can ban_bai1_laptrinhwebphp.com
Php can ban_bai1_laptrinhwebphp.comPhp can ban_bai1_laptrinhwebphp.com
Php can ban_bai1_laptrinhwebphp.com
 
Os xmldomphp
Os xmldomphpOs xmldomphp
Os xmldomphp
 
Os php-7oohabits
Os php-7oohabitsOs php-7oohabits
Os php-7oohabits
 
Os php-5.3new1
Os php-5.3new1Os php-5.3new1
Os php-5.3new1
 
Lap trinh web dong voi php my sql
Lap trinh web dong voi php my sqlLap trinh web dong voi php my sql
Lap trinh web dong voi php my sql
 
Kentcources 110109221507-phpapp01
Kentcources 110109221507-phpapp01Kentcources 110109221507-phpapp01
Kentcources 110109221507-phpapp01
 
Php day4
Php day4Php day4
Php day4
 
Hay php architect eav modeling
Hay php architect   eav modelingHay php architect   eav modeling
Hay php architect eav modeling
 
Haiphongit.com.tai lieu-php.my sql-thiet-ke-web-dong
Haiphongit.com.tai lieu-php.my sql-thiet-ke-web-dongHaiphongit.com.tai lieu-php.my sql-thiet-ke-web-dong
Haiphongit.com.tai lieu-php.my sql-thiet-ke-web-dong
 
Haiphongit.com.tai lieu-laptrinh ph-pvamysql
Haiphongit.com.tai lieu-laptrinh ph-pvamysqlHaiphongit.com.tai lieu-laptrinh ph-pvamysql
Haiphongit.com.tai lieu-laptrinh ph-pvamysql
 
Chuong07 php
Chuong07 phpChuong07 php
Chuong07 php
 
Bai th08 php voi csdl
Bai th08 php voi csdlBai th08 php voi csdl
Bai th08 php voi csdl
 
Haiphongit.com.tai lieu-learning-php-my sql
Haiphongit.com.tai lieu-learning-php-my sqlHaiphongit.com.tai lieu-learning-php-my sql
Haiphongit.com.tai lieu-learning-php-my sql
 
Hd lap pttkht2008
Hd lap pttkht2008Hd lap pttkht2008
Hd lap pttkht2008
 
Joomla administratormanual vi_20060206
Joomla administratormanual vi_20060206Joomla administratormanual vi_20060206
Joomla administratormanual vi_20060206
 
Canbanvethietkevalaptrinhgame
CanbanvethietkevalaptrinhgameCanbanvethietkevalaptrinhgame
Canbanvethietkevalaptrinhgame
 
C1
C1C1
C1
 
Building websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menu
Building websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menuBuilding websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menu
Building websites-with-joomla-1-5-sample-chapter-chapter-7-the-menus-menu
 
Eclipse pdt indigo release review
Eclipse pdt   indigo release reviewEclipse pdt   indigo release review
Eclipse pdt indigo release review
 
Bai tap lap trinh web voi joomla csau
Bai tap   lap trinh web voi joomla csauBai tap   lap trinh web voi joomla csau
Bai tap lap trinh web voi joomla csau
 

Recently uploaded

20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...
20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...
20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...Nguyen Thanh Tu Collection
 
Tien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdf
Tien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdfTien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdf
Tien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdfThoNguyn989738
 
40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...
40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...
40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...Nguyen Thanh Tu Collection
 
BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...
BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...
BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...Nguyen Thanh Tu Collection
 
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...Nguyen Thanh Tu Collection
 
Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...
Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...
Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...lamluanvan.net Viết thuê luận văn
 
Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...
Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...
Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...lamluanvan.net Viết thuê luận văn
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...Nguyen Thanh Tu Collection
 
Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)
Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)
Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)LinhV602347
 
Unit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docx
Unit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docxUnit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docx
Unit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docxabilitygeneraluse
 
xemsomenh.com-Bố cục của lá số tử vi như thế nào.pdf
xemsomenh.com-Bố cục của lá số tử vi như thế nào.pdfxemsomenh.com-Bố cục của lá số tử vi như thế nào.pdf
xemsomenh.com-Bố cục của lá số tử vi như thế nào.pdfXem Số Mệnh
 
CHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜI
CHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜICHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜI
CHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜInguyendoan3122102508
 
nghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docx
nghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docxnghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docx
nghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docxThoNguyn989738
 
ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...
ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...
ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...Nguyen Thanh Tu Collection
 
Nghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdf
Nghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdfNghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdf
Nghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdfThoNguyn989738
 
BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...
BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...
BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...Nguyen Thanh Tu Collection
 
15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...
15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...
15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...Nguyen Thanh Tu Collection
 
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...
20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...
20 ĐỀ DỰ ĐOÁN - PHÁT TRIỂN ĐỀ MINH HỌA BGD KỲ THI TỐT NGHIỆP THPT NĂM 2024 MÔ...
 
Tien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdf
Tien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdfTien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdf
Tien De Ra Tien Dau Tu Tai Chinh Thong Minh - Duncan Bannatyne.pdf
 
40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...
40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...
40 ĐỀ LUYỆN THI ĐÁNH GIÁ NĂNG LỰC ĐẠI HỌC QUỐC GIA HÀ NỘI NĂM 2024 (ĐỀ 31-39)...
 
BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...
BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...
BÀI TẬP DẠY THÊM TOÁN LỚP 12 SÁCH MỚI THEO FORM THI MỚI BGD 2025 - CHÂN TRỜI ...
 
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
 
Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...
Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...
Báo cáo thực tập tốt nghiệp Phân tích thực trạng hoạt động bán hàng tại Công ...
 
Talk Academy Presentation 2024 (ENG) MICE.pdf
Talk Academy Presentation 2024 (ENG) MICE.pdfTalk Academy Presentation 2024 (ENG) MICE.pdf
Talk Academy Presentation 2024 (ENG) MICE.pdf
 
Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...
Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...
Đồ án tốt nghiệp “Khảo sát ý thức bảo vệ môi trường của các hộ kinh doanh ăn ...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)
Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)
Đề cương môn Xã hội Chủ nghĩa Khoa học (sơ lược)
 
Unit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docx
Unit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docxUnit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docx
Unit 1 - Luyện chuyên sâu Ngữ pháp và Bài tập tiếng Anh 6 (HS).docx
 
xemsomenh.com-Bố cục của lá số tử vi như thế nào.pdf
xemsomenh.com-Bố cục của lá số tử vi như thế nào.pdfxemsomenh.com-Bố cục của lá số tử vi như thế nào.pdf
xemsomenh.com-Bố cục của lá số tử vi như thế nào.pdf
 
CHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜI
CHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜICHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜI
CHƯƠNG 5. TTHCM VỀ VĂN HÓA, ĐẠO ĐỨC, CON NGƯỜI
 
nghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docx
nghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docxnghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docx
nghiên cứu một số kĩ thuật chiết xuất dược liệu (1).docx
 
Đồ án Công Nghệ Truyền Số Liệu L3VPN MPLS
Đồ án Công Nghệ Truyền Số Liệu L3VPN MPLSĐồ án Công Nghệ Truyền Số Liệu L3VPN MPLS
Đồ án Công Nghệ Truyền Số Liệu L3VPN MPLS
 
ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...
ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...
ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 THPT MÔN TOÁN CÁC TỈNH NĂM HỌC 2023-2024 CÓ ...
 
Nghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdf
Nghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdfNghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdf
Nghe Tay Trai Hai Ra Tien - Chris Guillebeau (1).pdf
 
BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...
BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...
BÀI TẬP DẠY THÊM HÓA HỌC LỚP 12 - CẢ NĂM - THEO FORM THI MỚI BGD 2025 (DÙNG C...
 
15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...
15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...
15 ĐỀ THI THỬ TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 SỞ GIÁO...
 
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 11 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-...
 

Ung dung web chuong 8

  • 1. Chương 8 Tùy biến điều khiển trong ASP.NET
  • 2. Mục đích  Xác định cần thiết của việc tạo custom controls  Tạo điều khiển đơn giảng dùng ASP.NET  Tạo Composite control dùng C#  Sử dụng sự kiện với custom controls Exploring ASP.NET / Session 15/ 2 of 22
  • 3. Controls  Các lớp được xây dựng cho việc tái sử dụng mã  cần thiết tái sử dụng lại các điều khiển giao diện người dùng  Control giúp tái sử dụng một cách trực quan cũng như bổ sung các chức năng tương ứng  Giúp đóng gói các khả năng và phân phối  ASP.NET controls dùng cho Web để tạo HTML hoặc WML, hiển thị trên trình duyệt người dùng Exploring ASP.NET / Session 15/ 3 of 22
  • 4. Controls … A ssfffghfio i Assfffg hfioi J hjkhjkhjkhj J hjkhjkhj khj Uy uuiyu iy ui Uy uu iy uiyu i ghg hghjgg g g hghg hjg gg Code for a datagrid Code for a dataview A ssfffghfioi Jhjkhjkhjkhj Uyuu iyuiyui ghghghjggg Code for a Label Assfffghfioi A ssfffghfioi Jhjkhjkhjkhj Jhj khjkhjkhj Uyuu iyuiyui Uyu uiyu iyu i ghghghjggg Code for a radiobutton g hg hghj ggg A ssfffghfioi Jhjkhjkhjkhj Code for a textbox Uyuu iyuiyui ghghghjggg Code for a checkbox Assfffghfioi Jhjkhjkhjkhj Uyuu iyuiyui ghghghjggg Code for a button Exploring ASP.NET / Session 15/ 4 of 22
  • 5. Custom Controls Tạo theo 2 cách C# ASP.NET like Page Pagelets Exploring ASP.NET / Session 15/ 5 of 22
  • 6. Custom Control sử dụng Label Control MyLabel.ascx <% @Control Language="C#" Debug="True" %> <ASP:Label id="lblOne" runat="server" style="color:Red; font-family: arial; font-size=40pt"></asp:Label> <script language="C#" runat="server"> public string MyText { get { // Do Nothing return(lblOne.Text); } set { lblOne.Text = value; } Exploring ASP.NET / Session 15/ 6 of 22
  • 7. Custom Control dùng Label Control } </script> Label.aspx <% @Register Tagprefix="MyFirstControl" TagName="MyLbl" Src="MyLabel.ascx" %> <MyFirstControl:MyLbl runat="Server" id ="AllMine" MyText="My first custom control !!!" /> Exploring ASP.NET / Session 15/ 7 of 22
  • 8. Custom Controls dùng C# Điều khiển này được viết hoàn toàn dùng C# mà không cần dùng bất cứ điều khiển ASP.Net nào Repeater.cs using System; using System.Web; using System.Web.UI; namespace MyOwnControls { public class TextRepeater : Control { protected override void Render(HtmlTextWriter writer) { int intCount; Exploring ASP.NET / Session 15/ 8 of 22
  • 9. Custom Controls dùng C# for (intCount=1; intCount<=3; intCount++) { writer.Write ("<h1>This is a custom control</h1> <br>"); } } } } Mã được lưu trong tập tin cs và được biên dịch thành dll và nên được đặt vào trong thư mục bin của ứng dụng csc /t:library / r:System.dll,System.Web.Dll Repeater.cs Exploring ASP.NET / Session 15/ 9 of 22
  • 10. Custom Controls dùng C# Sử dụng trong rang ASP.Net <% @Register TagPrefix="Mine" Namespace="MyOwnControls" Assembly="Repeater" %> <html> <title>Custom control using C#</title> <body> <Mine:TextRepeater runat="server" /> </body> </html> Exploring ASP.NET / Session 15/ 10 of 22
  • 11. Thuộc tính của Custom Controls  Đế cho phép sử dụng tốt hơn các control, chúng ta có thể tạo thuộc tính cho các điều khiển  Các thuộc tính này có thể thay đổi một cách tự động NewRepeater. cs using System; using System.Web; using System.Web.UI; namespace MyOwnControls { public class TextRepeater : Control { public int timesToRepeat; Exploring ASP.NET / Session 15/ 11 of 22
  • 12. Properties of Custom Controls public string myText; public int TimesToRepeat { get { return timesToRepeat; } set { if (timesToRepeat > 10) throw new ArgumentException ("The text should not be repeated more than 10 times"); else timesToRepeat = value; } } Exploring ASP.NET / Session 15/ 12 of 22
  • 13. Properties of Custom Controls public string MyText { get { return myText; } set { if (myText.Length > 25) throw new ArgumentException("The text should not be more than 25 characters"); else myText = value; } } Exploring ASP.NET / Session 15/ 13 of 22
  • 14. Properties of Custom Controls protected override void Render(HtmlTextWriter writer) { for (int Count = 1; Count <= TimesToRepeat; Count++) { writer.Write("<h1>" + MyText + "</h1><br>"); } } } } Exploring ASP.NET / Session 15/ 14 of 22
  • 15. Composite Controls  Các control đơn giản có thể kết hợp với nhau để tạo các control phức tạp  Composite controls.  Composite controls có thể bao hàm các custom controls, cũng như các control của windows  Mỗi trang asp.net bao gồm ít nhất một control  là mộtcomposite control Exploring ASP.NET / Session 15/ 15 of 22
  • 16. Composite Controls – Ví dụ Composite.c s using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace MyOwnControls { public class MyComposition : Control, INamingContainer { public int Val { get { this.EnsureChildControls(); return Int32.Parse (((TextBox) Controls[1]). Text); } Exploring ASP.NET / Session 15/ 16 of 22
  • 17. Composite Controls - Ví dụ set { this.EnsureChildControls(); ((TextBox)Controls[1]).Text = value.ToString(); } } protected override void CreateChildControls() { this.Controls.Add(new LiteralControl("<h3>Value: ")); TextBox box = new TextBox(); box.Text = "0"; this.Controls.Add(box); this.Controls.Add(new LiteralControl("</h3>")); } } } Exploring ASP.NET / Session 15/ 17 of 22
  • 18. Composite Controls – Ví dụ composite control được tạo và sử dụng giống như các control khác trong asp.net Composite.asp x <% @Register TagPrefix="MyOwnControls" Namespace="MyOwnControls" Assembly="Composite" %> <HTML> <title>Composite Controls</title> <script language="C#" runat="server"> private void AddBtn_Click(Object sender, EventArgs e) { MyComposition1.Val = MyComposition1.Val + 1; } private void SubtractBtn_Click(Object sender, EventArgs e) Exploring ASP.NET / Session 15/ 18 of 22
  • 19. Composite Controls – Ví dụ { MyComposition1.Val = MyComposition1.Val - 1; } </script> <body> <form method="post" action="ThisPage.aspx" runat= "server" ID="Form1"> <MyOwnControls:MyComposition id="MyComposition1" runat="server" /> <asp:button text="Add" OnClick="AddBtn_Click" runat="server" ID="btnAdd" /> <asp:button text="Subtract" OnClick="SubtractBtn_ Click" runat="server" ID="btnSubtract" /> </form> </body> </HTML> Exploring ASP.NET / Session 15/ 19 of 22
  • 20. Composite Controls – Ví dụ Exploring ASP.NET / Session 15/ 20 of 22
  • 21. Summary  Controls giúp tái sử dụng mã cũng như chức năng của nó  Custom web controls được tạo theo 2 cách:  Pagelets  Web Controls dùng C#  Pagelets là custom control nhưng giống một trang asp, và có phần mở rộng là .ascx.  Web Controls render HTML tụ động.  Custom Controls là kết hợp của các control khác  Giao diện System.Web.UI.INamingContainer không có phương thức, ASP.Net dùng để tạo các unique ID. Exploring ASP.NET / Session 15/ 21 of 22