SlideShare a Scribd company logo
2
Most read
4
Most read
6
Most read
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

PDF
Asp .net web form fundamentals
PPT
android activity
PPTX
PPTX
Validation Controls in asp.net
PPTX
Introduction to Angularjs
PPSX
ADO.NET
PPTX
Cohesion and coupling
Asp .net web form fundamentals
android activity
Validation Controls in asp.net
Introduction to Angularjs
ADO.NET
Cohesion and coupling

What's hot (20)

PPT
Requirement specification (SRS)
PPTX
ReactJS presentation.pptx
PPT
PPSX
ASP.NET Web form
PPTX
Windows form application - C# Training
PDF
CSS Positioning Elements.pdf
PPTX
Java Database Connectivity (JDBC)
PDF
Asp.net state management
PPTX
Javascript operators
PPTX
Database connectivity in asp.net
PDF
Creating simple component
PPT
Asp.net control
PDF
JavaScript - Chapter 12 - Document Object Model
PDF
Lecture-1: Introduction to web engineering - course overview and grading scheme
PPT
Server Controls of ASP.Net
PPTX
Servlets
PDF
Android intents
PDF
ASP.NET Unit-2.pdf
Requirement specification (SRS)
ReactJS presentation.pptx
ASP.NET Web form
Windows form application - C# Training
CSS Positioning Elements.pdf
Java Database Connectivity (JDBC)
Asp.net state management
Javascript operators
Database connectivity in asp.net
Creating simple component
Asp.net control
JavaScript - Chapter 12 - Document Object Model
Lecture-1: Introduction to web engineering - course overview and grading scheme
Server Controls of ASP.Net
Servlets
Android intents
ASP.NET Unit-2.pdf
Ad

Similar to Custom Controls in ASP.net (20)

PPTX
ASP DOT NET
PPTX
Asp PPT (.NET )
PPSX
12 asp.net session17
PPT
SynapseIndia creating asp controls programatically development
PPT
ASP.NET Session 9
PPTX
Client control
PPTX
Overview of ASP.Net by software outsourcing company india
PPT
Asp.net server controls
PPS
12 asp.net session17
PDF
Alfresco : Implementing Business Rules
PDF
Visual studio 2008 asp net
PPTX
Streamlining React Component Development and Sharing with bit.pptx
PPTX
How to Perform Test Automation With Gauge & Selenium Framework
PPTX
Custom control in asp.net
PDF
Balancing UX Consistency and Developer Productivity in a Design System
PPTX
UNIT1.pptx Introduction to ASP.NET IN IMR COLLEGE JALGOAN
ODP
AD207 Presentation
PPSX
03 asp.net session04
PPTX
User Tutorial
ASP DOT NET
Asp PPT (.NET )
12 asp.net session17
SynapseIndia creating asp controls programatically development
ASP.NET Session 9
Client control
Overview of ASP.Net by software outsourcing company india
Asp.net server controls
12 asp.net session17
Alfresco : Implementing Business Rules
Visual studio 2008 asp net
Streamlining React Component Development and Sharing with bit.pptx
How to Perform Test Automation With Gauge & Selenium Framework
Custom control in asp.net
Balancing UX Consistency and Developer Productivity in a Design System
UNIT1.pptx Introduction to ASP.NET IN IMR COLLEGE JALGOAN
AD207 Presentation
03 asp.net session04
User Tutorial
Ad

More from kunj desai (9)

PPTX
OLAP operations
PPT
Bottom - Up Parsing
PPT
Loaders and Linkers
PPT
Binary Search
PPTX
Introduction to 8085 microprocessor
PPT
JDBC Connectivity Model
PPT
Minimization of DFA
PPT
php databse handling
PPTX
Concept of constructors
OLAP operations
Bottom - Up Parsing
Loaders and Linkers
Binary Search
Introduction to 8085 microprocessor
JDBC Connectivity Model
Minimization of DFA
php databse handling
Concept of constructors

Recently uploaded (20)

PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPT
Project quality management in manufacturing
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
Digital Logic Computer Design lecture notes
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Foundation to blockchain - A guide to Blockchain Tech
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Project quality management in manufacturing
Lesson 3_Tessellation.pptx finite Mathematics
Digital Logic Computer Design lecture notes
Lecture Notes Electrical Wiring System Components
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Mechanical Engineering MATERIALS Selection
Foundation to blockchain - A guide to Blockchain Tech
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
CH1 Production IntroductoryConcepts.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...

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