SlideShare a Scribd company logo
1 of 14
Custom Control in ASP.net
• Name : Kunj Desai
• Enrollment no.:140950107022
• Branch: CSE-A
• Semester: 6th
• Year : 2017
Custom Control in ASP.net
• Custom controls are deployed as individual assemblies. They are
compiled into a Dynamic Link Library DLL and used as any other
ASP.NET server control. They could be created in either of the
following way:
1. By deriving a custom control from an existing control.
2. By composing a new custom control combing two or more
existing controls.
3. By deriving from the base control class.
Custom Control in ASP.net
• To understand the concept, let us create a custom control, which will
simply render a text message on the browser. To create this control,
take the following steps:
• Create a new website. Right click the solution nottheproject at the top
of the tree in the Solution Explorer.
Custom Control in ASP.net
• In the New Project dialog box, select ASP.NET Server Control from the project
templates.
• The above step adds a new project and creates a complete custom control to the
solution, called
• ServerControl1. In this example, let us name the project Custom Controls. To use
this control, this must be added as a reference to the web site before registering it
on a page.
Custom Control in ASP.net
• To add a reference to the existing project, right click on the project
notthesolution, and click Add Reference. To add a reference to the
existing project, right click on the project notthesolution, and click Add
Reference.
• Select the Custom Controls project from the Projects tab of the Add
Reference dialog box. The Solution Explorer should show the
reference.
Custom Control in ASP.net
• To use the control on a page, add the Register directive just below the @Page directive:
<%@ Register Assembly="Custom Controls" Namespace ="Custom
Controls" TagPrefix="ccs" %>
• Further, you can use the control, similar to any other controls.
<form >
<div>
<ccs:ServerControl1 runat="server" Text = "I am a Custom Server
Control" />
</div>
</form >
Custom Control in ASP.net
• When executed, the Text property of the control is rendered on the
browser as shown:
• In the previous example, the value for the Text property of the custom
control was set. ASP.NET added this property by default, when the
control was created.
Custom Control in ASP.net
Custom Control in ASP.net
• The above code is automatically generated for a custom control.
Events and methods could be added to the custom control class.
 Example:
• Let us expand the previous custom control named SeverControl1. Let
us give it a method named checkpalindrome, which gives it a power to
check for palindromes.
• Palindromes are words/literals that spell the same when reversed. For
example, Malayalam, madam, saras, etc.
Custom Control in ASP.net
Custom Control in ASP.net
Custom Control in ASP.net
• When you change the code for the control, you must build the solution by clicking
Build --> Build Solution, so that the changes are reflected in your project. Add a text
box and a button control to the page, so that the user can provide a text, it is checked
for palindrome, when the button is clicked.
 Form:
<form id="form1" runat="server">
<div> Enter a word: <br />
<asp:TextBox ID="TextBox1" runat="server" style="width:198px"> </asp:TextBox>
<br /> <br />
<asp:Button ID="Button1" runat="server onclick="Button1_Click" Text="Check
Palindrome" style="width:132px" /> <br /> <br /> <ccs:ServerControl1
ID="ServerControl11" runat="server" Text = "" />
</div>
</form>
Custom Control in ASP.net
• The Click event handler for the button simply copies the text from the
text box to the text property of the custom control as shown below:
protected void Button1_Click(object sender, EventArgs e)
{
this.ServerControl11.Text = this.TextBox1.Text;
}
• When executed, the control successfully checks palindromes.
Custom Control in ASP.net
 Observe the following:
1. When you add a reference to the custom control, it is added to the toolbox and you
can directly use it from the toolbox similar to any other control.
2. The Render Contents method of the custom control class is overridden here, as
you can add your own methods and events.
3. The Render Contents method takes a parameter of HtmlTextWriter type, which is
responsible for

More Related Content

What's hot

Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategiesSHREEHARI WADAWADAGI
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memoryAshish Kumar
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.netBhumivaghasiya
 
Process management
Process managementProcess management
Process managementBirju Tank
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assuranceAman Adhikari
 
Database Design
Database DesignDatabase Design
Database Designlearnt
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 
Linux network file system (nfs)
Linux   network file system (nfs)Linux   network file system (nfs)
Linux network file system (nfs)Raghu nath
 
Software project management- Software Engineering
Software project management- Software EngineeringSoftware project management- Software Engineering
Software project management- Software EngineeringMuhammad Yousuf Abdul Qadir
 
Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7mohammad hossein Jalili
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)Prakhar Maurya
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static ModelingSaurabh Kumar
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.Ravi Kumar Patel
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architectureYisal Khan
 

What's hot (20)

Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategies
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memory
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.net
 
Process management
Process managementProcess management
Process management
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 
Database Design
Database DesignDatabase Design
Database Design
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Linux network file system (nfs)
Linux   network file system (nfs)Linux   network file system (nfs)
Linux network file system (nfs)
 
Software project management- Software Engineering
Software project management- Software EngineeringSoftware project management- Software Engineering
Software project management- Software Engineering
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static Modeling
 
Anomalies in database
Anomalies in databaseAnomalies in database
Anomalies in database
 
Java threading
Java threadingJava threading
Java threading
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architecture
 

Similar to Custom Controls in ASP.net

12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17Vivek chan
 
SynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseindiappsdevelopment
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9Sisir Ghosh
 
Client control
Client controlClient control
Client controlSireesh K
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaJignesh Aakoliya
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controlsRaed Aldahdooh
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17Niit Care
 
Alfresco : Implementing Business Rules
Alfresco : Implementing Business RulesAlfresco : Implementing Business Rules
Alfresco : Implementing Business RulesWildan Maulana
 
Streamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptxStreamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptxShubhamJayswal6
 
How to Perform Test Automation With Gauge & Selenium Framework
How to Perform Test Automation With Gauge & Selenium Framework How to Perform Test Automation With Gauge & Selenium Framework
How to Perform Test Automation With Gauge & Selenium Framework Sarah Elson
 
Custom control in asp.net
Custom control in asp.netCustom control in asp.net
Custom control in asp.netSireesh K
 
Balancing UX Consistency and Developer Productivity in a Design System
Balancing UX Consistency and Developer Productivity in a Design SystemBalancing UX Consistency and Developer Productivity in a Design System
Balancing UX Consistency and Developer Productivity in a Design Systemuxpin
 
AD207 Presentation
AD207 PresentationAD207 Presentation
AD207 Presentationmackejo1
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04Vivek chan
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.netSireesh K
 

Similar to Custom Controls in ASP.net (20)

ASP DOT NET
ASP DOT NETASP DOT NET
ASP DOT NET
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
SynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically development
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9
 
Client control
Client controlClient control
Client control
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
Alfresco : Implementing Business Rules
Alfresco : Implementing Business RulesAlfresco : Implementing Business Rules
Alfresco : Implementing Business Rules
 
Visual studio 2008 asp net
Visual studio 2008 asp netVisual studio 2008 asp net
Visual studio 2008 asp net
 
Streamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptxStreamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptx
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
How to Perform Test Automation With Gauge & Selenium Framework
How to Perform Test Automation With Gauge & Selenium Framework How to Perform Test Automation With Gauge & Selenium Framework
How to Perform Test Automation With Gauge & Selenium Framework
 
Custom control in asp.net
Custom control in asp.netCustom control in asp.net
Custom control in asp.net
 
Balancing UX Consistency and Developer Productivity in a Design System
Balancing UX Consistency and Developer Productivity in a Design SystemBalancing UX Consistency and Developer Productivity in a Design System
Balancing UX Consistency and Developer Productivity in a Design System
 
AD207 Presentation
AD207 PresentationAD207 Presentation
AD207 Presentation
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
User Tutorial
User TutorialUser Tutorial
User Tutorial
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 

More from kunj desai

OLAP operations
OLAP operationsOLAP operations
OLAP operationskunj desai
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsingkunj desai
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkerskunj desai
 
Introduction to 8085 microprocessor
Introduction to 8085 microprocessorIntroduction to 8085 microprocessor
Introduction to 8085 microprocessorkunj desai
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Modelkunj desai
 
Requirement specification (SRS)
Requirement specification (SRS)Requirement specification (SRS)
Requirement specification (SRS)kunj desai
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFAkunj desai
 
php databse handling
php databse handlingphp databse handling
php databse handlingkunj desai
 
Concept of constructors
Concept of constructorsConcept of constructors
Concept of constructorskunj desai
 

More from kunj desai (10)

OLAP operations
OLAP operationsOLAP operations
OLAP operations
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkers
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Introduction to 8085 microprocessor
Introduction to 8085 microprocessorIntroduction to 8085 microprocessor
Introduction to 8085 microprocessor
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
Requirement specification (SRS)
Requirement specification (SRS)Requirement specification (SRS)
Requirement specification (SRS)
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
php databse handling
php databse handlingphp databse handling
php databse handling
 
Concept of constructors
Concept of constructorsConcept of constructors
Concept of constructors
 

Recently uploaded

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 

Recently uploaded (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 

Custom Controls in ASP.net

  • 1. Custom Control in ASP.net • Name : Kunj Desai • Enrollment no.:140950107022 • Branch: CSE-A • Semester: 6th • Year : 2017
  • 2. Custom Control in ASP.net • Custom controls are deployed as individual assemblies. They are compiled into a Dynamic Link Library DLL and used as any other ASP.NET server control. They could be created in either of the following way: 1. By deriving a custom control from an existing control. 2. By composing a new custom control combing two or more existing controls. 3. By deriving from the base control class.
  • 3. Custom Control in ASP.net • To understand the concept, let us create a custom control, which will simply render a text message on the browser. To create this control, take the following steps: • Create a new website. Right click the solution nottheproject at the top of the tree in the Solution Explorer.
  • 4. Custom Control in ASP.net • In the New Project dialog box, select ASP.NET Server Control from the project templates. • The above step adds a new project and creates a complete custom control to the solution, called • ServerControl1. In this example, let us name the project Custom Controls. To use this control, this must be added as a reference to the web site before registering it on a page.
  • 5. Custom Control in ASP.net • To add a reference to the existing project, right click on the project notthesolution, and click Add Reference. To add a reference to the existing project, right click on the project notthesolution, and click Add Reference. • Select the Custom Controls project from the Projects tab of the Add Reference dialog box. The Solution Explorer should show the reference.
  • 6. Custom Control in ASP.net • To use the control on a page, add the Register directive just below the @Page directive: <%@ Register Assembly="Custom Controls" Namespace ="Custom Controls" TagPrefix="ccs" %> • Further, you can use the control, similar to any other controls. <form > <div> <ccs:ServerControl1 runat="server" Text = "I am a Custom Server Control" /> </div> </form >
  • 7. Custom Control in ASP.net • When executed, the Text property of the control is rendered on the browser as shown: • In the previous example, the value for the Text property of the custom control was set. ASP.NET added this property by default, when the control was created.
  • 9. Custom Control in ASP.net • The above code is automatically generated for a custom control. Events and methods could be added to the custom control class.  Example: • Let us expand the previous custom control named SeverControl1. Let us give it a method named checkpalindrome, which gives it a power to check for palindromes. • Palindromes are words/literals that spell the same when reversed. For example, Malayalam, madam, saras, etc.
  • 10. Custom Control in ASP.net
  • 11. Custom Control in ASP.net
  • 12. Custom Control in ASP.net • When you change the code for the control, you must build the solution by clicking Build --> Build Solution, so that the changes are reflected in your project. Add a text box and a button control to the page, so that the user can provide a text, it is checked for palindrome, when the button is clicked.  Form: <form id="form1" runat="server"> <div> Enter a word: <br /> <asp:TextBox ID="TextBox1" runat="server" style="width:198px"> </asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server onclick="Button1_Click" Text="Check Palindrome" style="width:132px" /> <br /> <br /> <ccs:ServerControl1 ID="ServerControl11" runat="server" Text = "" /> </div> </form>
  • 13. Custom Control in ASP.net • The Click event handler for the button simply copies the text from the text box to the text property of the custom control as shown below: protected void Button1_Click(object sender, EventArgs e) { this.ServerControl11.Text = this.TextBox1.Text; } • When executed, the control successfully checks palindromes.
  • 14. Custom Control in ASP.net  Observe the following: 1. When you add a reference to the custom control, it is added to the toolbox and you can directly use it from the toolbox similar to any other control. 2. The Render Contents method of the custom control class is overridden here, as you can add your own methods and events. 3. The Render Contents method takes a parameter of HtmlTextWriter type, which is responsible for