SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Destaque

兒童前期親職教育
兒童前期親職教育兒童前期親職教育
兒童前期親職教育
Kuo-Yi Chen
 
Group 1 case 1
Group 1 case 1Group 1 case 1
Group 1 case 1
cookj111
 
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
Darlene 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_mishra
IBM
 
Profession
ProfessionProfession
Profession
pmizuo
 
200901011455420 申請連任簡報
200901011455420 申請連任簡報200901011455420 申請連任簡報
200901011455420 申請連任簡報
Kuo-Yi Chen
 
Electrospn 17 yalcinkaya-full
Electrospn 17 yalcinkaya-fullElectrospn 17 yalcinkaya-full
Electrospn 17 yalcinkaya-full
miroli
 
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
Giang Nguyễn
 
Team Dustin Wentzel
Team Dustin WentzelTeam Dustin Wentzel
Team Dustin Wentzel
Annie Welbie
 
опрокидывающиеся сковороды Rus
опрокидывающиеся сковороды Rusопрокидывающиеся сковороды Rus
опрокидывающиеся сковороды Rus
Sokirianskiy&Lazerson School
 

Destaque (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
 

Semelhante a 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_csharp
ngohanty13
 
Ajax control toolkit
Ajax control toolkitAjax control toolkit
Ajax control toolkit
Nguyen Huy
 
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
Dao Uit
 

Semelhante a 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
 
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
 
đề 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...
 
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
 

Mais de 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.com
Giang 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 sql
Giang Nguyễn
 
Kentcources 110109221507-phpapp01
Kentcources 110109221507-phpapp01Kentcources 110109221507-phpapp01
Kentcources 110109221507-phpapp01
Giang Nguyễn
 
Hay php architect eav modeling
Hay php architect   eav modelingHay php architect   eav modeling
Hay php architect eav modeling
Giang 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-dong
Giang 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-pvamysql
Giang 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 sql
Giang Nguyễn
 
Joomla administratormanual vi_20060206
Joomla administratormanual vi_20060206Joomla administratormanual vi_20060206
Joomla administratormanual vi_20060206
Giang Nguyễn
 
Canbanvethietkevalaptrinhgame
CanbanvethietkevalaptrinhgameCanbanvethietkevalaptrinhgame
Canbanvethietkevalaptrinhgame
Giang 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-menu
Giang Nguyễn
 
Eclipse pdt indigo release review
Eclipse pdt   indigo release reviewEclipse pdt   indigo release review
Eclipse pdt indigo release review
Giang 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 csau
Giang Nguyễn
 

Mais de 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
 

Último

SLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdf
SLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdfSLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdf
SLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdf
hoangtuansinh1
 

Último (20)

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...
 
ĐỀ CHÍNH THỨC KỲ THI TUYỂN SINH VÀO LỚP 10 THPT CÁC TỈNH THÀNH NĂM HỌC 2020 –...
ĐỀ CHÍNH THỨC KỲ THI TUYỂN SINH VÀO LỚP 10 THPT CÁC TỈNH THÀNH NĂM HỌC 2020 –...ĐỀ CHÍNH THỨC KỲ THI TUYỂN SINH VÀO LỚP 10 THPT CÁC TỈNH THÀNH NĂM HỌC 2020 –...
ĐỀ CHÍNH THỨC KỲ THI TUYỂN SINH VÀO LỚP 10 THPT CÁC TỈNH THÀNH NĂM HỌC 2020 –...
 
3-BẢNG MÃ LỖI CỦA CÁC HÃNG ĐIỀU HÒA .pdf - ĐIỆN LẠNH BÁCH KHOA HÀ NỘI
3-BẢNG MÃ LỖI CỦA CÁC HÃNG ĐIỀU HÒA .pdf - ĐIỆN LẠNH BÁCH KHOA HÀ NỘI3-BẢNG MÃ LỖI CỦA CÁC HÃNG ĐIỀU HÒA .pdf - ĐIỆN LẠNH BÁCH KHOA HÀ NỘI
3-BẢNG MÃ LỖI CỦA CÁC HÃNG ĐIỀU HÒA .pdf - ĐIỆN LẠNH BÁCH KHOA HÀ NỘI
 
GIÁO TRÌNH KHỐI NGUỒN CÁC LOẠI - ĐIỆN LẠNH BÁCH KHOA HÀ NỘI
GIÁO TRÌNH  KHỐI NGUỒN CÁC LOẠI - ĐIỆN LẠNH BÁCH KHOA HÀ NỘIGIÁO TRÌNH  KHỐI NGUỒN CÁC LOẠI - ĐIỆN LẠNH BÁCH KHOA HÀ NỘI
GIÁO TRÌNH KHỐI NGUỒN CÁC LOẠI - ĐIỆN LẠNH BÁCH KHOA HÀ NỘI
 
Kiểm tra cuối học kì 1 sinh học 12 đề tham khảo
Kiểm tra cuối học kì 1 sinh học 12 đề tham khảoKiểm tra cuối học kì 1 sinh học 12 đề tham khảo
Kiểm tra cuối học kì 1 sinh học 12 đề tham khảo
 
PHƯƠNG THỨC VẬN TẢI ĐƯỜNG SẮT TRONG VẬN TẢI
PHƯƠNG THỨC VẬN TẢI ĐƯỜNG SẮT TRONG VẬN TẢIPHƯƠNG THỨC VẬN TẢI ĐƯỜNG SẮT TRONG VẬN TẢI
PHƯƠNG THỨC VẬN TẢI ĐƯỜNG SẮT TRONG VẬN TẢI
 
1 - MÃ LỖI SỬA CHỮA BOARD MẠCH BẾP TỪ.pdf
1 - MÃ LỖI SỬA CHỮA BOARD MẠCH BẾP TỪ.pdf1 - MÃ LỖI SỬA CHỮA BOARD MẠCH BẾP TỪ.pdf
1 - MÃ LỖI SỬA CHỮA BOARD MẠCH BẾP TỪ.pdf
 
TÀI LIỆU BỒI DƯỠNG HỌC SINH GIỎI KỸ NĂNG VIẾT ĐOẠN VĂN NGHỊ LUẬN XÃ HỘI 200 C...
TÀI LIỆU BỒI DƯỠNG HỌC SINH GIỎI KỸ NĂNG VIẾT ĐOẠN VĂN NGHỊ LUẬN XÃ HỘI 200 C...TÀI LIỆU BỒI DƯỠNG HỌC SINH GIỎI KỸ NĂNG VIẾT ĐOẠN VĂN NGHỊ LUẬN XÃ HỘI 200 C...
TÀI LIỆU BỒI DƯỠNG HỌC SINH GIỎI KỸ NĂNG VIẾT ĐOẠN VĂN NGHỊ LUẬN XÃ HỘI 200 C...
 
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...
 
SLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdf
SLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdfSLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdf
SLIDE - Tu van, huong dan cong tac tuyen sinh-2024 (đầy đủ chi tiết).pdf
 
sách sinh học đại cương - Textbook.pdf
sách sinh học đại cương   -   Textbook.pdfsách sinh học đại cương   -   Textbook.pdf
sách sinh học đại cương - Textbook.pdf
 
Giới thiệu Dự án Sản Phụ Khoa - Y Học Cộng Đồng
Giới thiệu Dự án Sản Phụ Khoa - Y Học Cộng ĐồngGiới thiệu Dự án Sản Phụ Khoa - Y Học Cộng Đồng
Giới thiệu Dự án Sản Phụ Khoa - Y Học Cộng Đồng
 
kinh tế chính trị mác lênin chương hai và hàng hoá và sxxhh
kinh tế chính trị mác lênin chương hai và hàng hoá và sxxhhkinh tế chính trị mác lênin chương hai và hàng hoá và sxxhh
kinh tế chính trị mác lênin chương hai và hàng hoá và sxxhh
 
SÁNG KIẾN ÁP DỤNG CLT (COMMUNICATIVE LANGUAGE TEACHING) VÀO QUÁ TRÌNH DẠY - H...
SÁNG KIẾN ÁP DỤNG CLT (COMMUNICATIVE LANGUAGE TEACHING) VÀO QUÁ TRÌNH DẠY - H...SÁNG KIẾN ÁP DỤNG CLT (COMMUNICATIVE LANGUAGE TEACHING) VÀO QUÁ TRÌNH DẠY - H...
SÁNG KIẾN ÁP DỤNG CLT (COMMUNICATIVE LANGUAGE TEACHING) VÀO QUÁ TRÌNH DẠY - H...
 
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...
 
Đề cương môn giải phẫu......................
Đề cương môn giải phẫu......................Đề cương môn giải phẫu......................
Đề cương môn giải phẫu......................
 
BỘ LUYỆN NGHE VÀO 10 TIẾNG ANH DẠNG TRẮC NGHIỆM 4 CÂU TRẢ LỜI - CÓ FILE NGHE.pdf
BỘ LUYỆN NGHE VÀO 10 TIẾNG ANH DẠNG TRẮC NGHIỆM 4 CÂU TRẢ LỜI - CÓ FILE NGHE.pdfBỘ LUYỆN NGHE VÀO 10 TIẾNG ANH DẠNG TRẮC NGHIỆM 4 CÂU TRẢ LỜI - CÓ FILE NGHE.pdf
BỘ LUYỆN NGHE VÀO 10 TIẾNG ANH DẠNG TRẮC NGHIỆM 4 CÂU TRẢ LỜI - CÓ FILE NGHE.pdf
 
GNHH và KBHQ - giao nhận hàng hoá và khai báo hải quan
GNHH và KBHQ - giao nhận hàng hoá và khai báo hải quanGNHH và KBHQ - giao nhận hàng hoá và khai báo hải quan
GNHH và KBHQ - giao nhận hàng hoá và khai báo hải quan
 
cac-cau-noi-tthcm.pdf-cac-cau-noi-tthcm-
cac-cau-noi-tthcm.pdf-cac-cau-noi-tthcm-cac-cau-noi-tthcm.pdf-cac-cau-noi-tthcm-
cac-cau-noi-tthcm.pdf-cac-cau-noi-tthcm-
 
1.DOANNGOCPHUONGTHAO-APDUNGSTEMTHIETKEBTHHHGIUPHSHOCHIEUQUA (1).docx
1.DOANNGOCPHUONGTHAO-APDUNGSTEMTHIETKEBTHHHGIUPHSHOCHIEUQUA (1).docx1.DOANNGOCPHUONGTHAO-APDUNGSTEMTHIETKEBTHHHGIUPHSHOCHIEUQUA (1).docx
1.DOANNGOCPHUONGTHAO-APDUNGSTEMTHIETKEBTHHHGIUPHSHOCHIEUQUA (1).docx
 

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