SlideShare a Scribd company logo
Using the standard control
Step1
step1
step2
Webform1.aspx
Design view
Design view-Adding a button and a
textbox
Webform1.aspx
Webform1.aspx.cs
Run application
Using the Validation control
• Using the RequiredFieldValidator Control
• In this example, we are adding two
RequiredFieldValidator controls on a Web
page for validating twoTextBox controls. The
RequiredFieldValidator controls ensure that
the two TextBox controls are not kept empty
by the user at runtime.
Design view
Default.aspx
• <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
• Inherits="_Default" %>
• <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
• "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
• <html xmlns="http://www.w3.org/1999/xhtml">
• <head runat="server">
• <title>RequiredFieldValidator Control Example</title>
• </head>
• <body>
• <form id="form1" runat="server">
• <div>
• <asp:Label ID="Label1" runat="server"
• Text="RequiredField Validator Control Example" Font-Bold="True"
• Font-Size="Medium" Font-Underline="True"></asp:Label>
• <br />
• <br />
• <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="Small"
• Text="User name:"></asp:Label>
• &nbsp;&nbsp;
• <asp:TextBox ID="TextBox1" runat="server" Height="22px"
• Width="175px"></asp:TextBox>
• <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
• ControlToValidate="TextBox1" ErrorMessage="User name can not be
• empty"></asp:RequiredFieldValidator>
• <br />
• <br />
• erver"
Cont..
• <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Small"
• Text="Password:"></asp:Label>
• &nbsp;&nbsp;&nbsp;&nbsp;
• <asp:TextBox ID="TextBox2" runat="server" Height="22px" TextMode="Password"
• Width="175px"></asp:TextBox>
• <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="s
• ControlToValidate="TextBox2" ErrorMessage="Password can not be
• empty"></asp:RequiredFieldValidator>
• <br />
• <br />
• <br />
• &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
• &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
• &nbsp;&nbsp;&nbsp;&nbsp;
• <asp:Button ID="Button1" runat="server" BackColor="Black" Font-Bold="True"
• Font-Size="Medium" ForeColor="White" Text="Submit" />
• </div>
• </form>
• </body>
• </html>
Using the RangeValidator Control: (Regular expression for date (^(19|20)dd([- /.])(0[1-9]|1[012])2(0[1-9]|[12][0-
9]|3[01])$)
Run the application
Using the RegularExpressionValidator
Control
• In this example, we are taking two
RegularExpressionValidator controls on a Web
page for validating two TextBox controls. It
ensures that the data (URL and email address)
entered in both the TextBox controls is valid
Design view
Run application
Using the CompareValidator Control
• In this example, we take a CompareValidator
control on a Web page, which validates the
third TextBox control. It ensures that the data
(password) entered in the third TextBox
control is exactly the same as the data
• (password) entered in the second TextBox
control.
Compare validator control
user interface and functionality.
Properties Description
Caption Gets or sets the caption for the calendar control.
CaptionAlign Gets or sets the alignment for the caption.
CellPadding Gets or sets the number of spaces between the data and the
Cell border.
CellSpacing Gets or sets the space between cells.
DayHeaderStyle Gets the style properties for the section that displays the
day of the week.
DayNameFormat Gets or sets format of days of the week.
DayStyle Gets the style properties for the days in the displayed month.
FirstDayOfWeek Gets or sets the day of week to display in the first column.
Cont..
NextMonthText Gets or sets the day of week to display in the first column.
NextPrevFormat Gets or sets the text for next month navigation control .The
default value is >
.
OtherMonthDayStyle Gets or sets the format of the next and previous month
navigation control.
PrevMonthText Gets the style properties for the days on the Calendar
control that are not in the displayed month.
SelectedDate Gets or sets the text for previous month navigation control.
The default value is <
.
ShowGridLines Gets or sets the value indicating whether the gridlines would
be shown.
Events
Events Description
SelectionChan
ged
It is raised when a day, a week or an entire month is selected.
DayRender t is raised when each data cell of the calendar control is
rendered.
VisibleMonth
Changed
It is raised when user changes a month.
Working with calendar controls
Default.aspx*
• <%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="Default.aspx.vb"
Inherits="rich_controls._Default" %>
• <asp:Content ID="Content1" runat="server" contentplaceholderid="MainContent">
• <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
• <div _designerregion="0">
• </div>
• <p>Todays date is:
• <asp:Label ID="lblday" runat="server"></asp:Label>
• </p>
• <p>Your Birday is:
• <asp:Label ID="lblbday" runat="server"></asp:Label>
• </p>
• </asp:Content>
Double click on the calendar
• Public Class _Default
• Inherits Page
• Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
• End Sub
• Protected Sub Calendar1_SelectionChanged(sender As Object, e
As EventArgs) Handles Calendar1.SelectionChanged
• lblday.Text = Calendar1.TodaysDate.ToShortDateString()
• lblbday.Text = Calendar1.SelectedDate.ToShortDateString()
• End Sub
• End Class
Run the Program
Creating custom controls with user
Controls
• ASP.NET allows the users to create controls.
These user defined controls are categorized
into:
• User controls
• Custom controls
User Conrols
• User controls behaves like miniature ASP.NETpages or
web forms, which could be used by many other pages.
These are derived from the system.Web.UI.UserControl
class. These controls have the following characteristics
• They have an .ascx extension.
• They may not contain any <html>, <body>,or <form>
tags.
• They have a Control directive instead of a Page
directive.
• To understand the concept, let us create a simple user
control, which will work as footer for the web pages.
To create and use the user control, take the following
steps:
Steps
• Create a new web application.
• Right click on the project folder on the Solution Explorer and
choose Add New Item.
• Select Web User Control from the Add New Item dialog box
and name it u1.ascx. Initially, the footer.ascx contains only a
Control directive.
• <%@ Control Language="C#" AutoEventWireup="true"
• CodeBehind=“u1.ascx.cs"
Inherits="customcontroldemo.footer" %>
User control(u1.ascx)
Register user control
• <%@ Page Title="Home Page" Language="VB"
MasterPageFile="~/Site.Master"
AutoEventWireup="true"
CodeBehind="Default.aspx.vb"
Inherits="WebApplication12._Default" %>
• <%@ Register Src="~/u1.ascx" TagName="u"
TagPrefix="ut" %>
Add a form to the project and use this control
• <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb"
Inherits="WebApplication12.WebForm1" %>
• <%@ Register Src="~/u1.ascx" TagName="u" TagPrefix="ut1" %>
• <!DOCTYPE html>
• <html xmlns="http://www.w3.org/1999/xhtml">
• <head runat="server">
• <title></title>
• </head>
• <body>
• <form id="form1" runat="server">
• <div>
•
• </div>
• <ut1:u ID="footer1" runat="server" />
• </form>
• </body>
• </html>
Run the application
Custom Control
• 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:
• By deriving a custom control from an existing control
• By composing a new custom control combing two or more existing
controls
• By deriving from the base control class
To understand the concept, let us create a custom control, which will simply
render a text message on the browser.
If you want to change the functionality of existing controls, such as a button
or label, you can directly derive the new class with these existing classes and
can change their default behavior.
In brief, the Control class provides the basic functionality by which you can
place it in the control tree for a Page class. The WebControl class adds the
functionality to the base Control class for displaying visual content on the
client computer. For example, you can use the WebControl class to control the
look and styles through properties like font, color, and height.
1. Create an empty ASP.NET web form
application
2. Right click on the web application and add ASP.NET server control:wc (name of the custom
control)
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
<DefaultProperty("Text"), ToolboxData("<{0}:wc runat=server></{0}:wc>")> _
Public Class wc Inherits WebControl
<Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String
Get
Dim s As String = CStr(ViewState("Text"))
If s Is Nothing Then
Return String.Empty
Else
Return s
End If
End Get
Set(ByVal Value As String)
ViewState("Text") = Value
End Set
End Property
Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
writer.Write("hello world from custom controls")
End Sub
End Class
Build the application
• Open a new or existing web form where you
can use the custom control.
Web form2.aspx file
• <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb"
Inherits="WebApplication15.WebForm2" %>
• <%@ Register assembly="WebApplication15" namespace="WebApplication15" tagprefix="cc1"
%>
• <!DOCTYPE html>
• <html xmlns="http://www.w3.org/1999/xhtml">
• <head runat="server">
• <title></title>
• </head>
• <body>
• <form id="form1" runat="server">
• <div>
•
• <cc1:wc ID="wc1" runat="server" />
•
• </div>
• </form>
• </body>
• </html>
Run the application

More Related Content

PPT
ASP.NET 03 - Working With Web Server Controls
PPT
Web controls
PPT
Asp.net server controls
PPSX
03 asp.net session04
PDF
Asp.net state management
PPT
Server Controls of ASP.Net
ZIP
ASP.Net Presentation Part1
PPTX
Controls
ASP.NET 03 - Working With Web Server Controls
Web controls
Asp.net server controls
03 asp.net session04
Asp.net state management
Server Controls of ASP.Net
ASP.Net Presentation Part1
Controls

What's hot (19)

PPTX
Ajax and ASP.NET AJAX
PDF
ASP.NET User Controls - 20090828
PPT
ASP.NET Session 10
PPT
Csphtp1 20
PPS
03 asp.net session04
PPSX
13 asp.net session19
PPTX
PDF
Aspnet mvc tutorial_01_cs
PPTX
Presentation on asp.net controls
PPTX
ASP.NET - Life cycle of asp
PPTX
Asp.net server control
PDF
RubyOnRails-Cheatsheet-BlaineKendall
DOCX
Adding a view
PDF
JavaScript - Chapter 14 - Form Handling
PPT
RichControl in Asp.net
PPTX
Parallelminds.asp.net with sp
PPTX
Academy PRO: React JS. Redux & Tooling
Ajax and ASP.NET AJAX
ASP.NET User Controls - 20090828
ASP.NET Session 10
Csphtp1 20
03 asp.net session04
13 asp.net session19
Aspnet mvc tutorial_01_cs
Presentation on asp.net controls
ASP.NET - Life cycle of asp
Asp.net server control
RubyOnRails-Cheatsheet-BlaineKendall
Adding a view
JavaScript - Chapter 14 - Form Handling
RichControl in Asp.net
Parallelminds.asp.net with sp
Academy PRO: React JS. Redux & Tooling
Ad

Similar to Asp PPT (.NET ) (20)

PPSX
12 asp.net session17
PDF
Visual studio 2008 asp net
PPT
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
PPTX
Overview of ASP.Net by software outsourcing company india
PPTX
ASP.NET Lecture 2
PPTX
SFDC UI - Introduction to Visualforce
PPT
Chapter 09
PPTX
PPTX
Ajax control asp.net
PPT
Asp.Net Ajax Component Development
PDF
C sharp and asp.net interview questions
PPTX
ASP.NET Lecture 6
PPT
Custom Controls in ASP.net
PPTX
User controls
PPS
11 asp.net session16
PPTX
Parallelminds.web partdemo1
PPTX
NET_Training.pptx
PDF
Angular - Chapter 4 - Data and Event Handling
12 asp.net session17
Visual studio 2008 asp net
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
Overview of ASP.Net by software outsourcing company india
ASP.NET Lecture 2
SFDC UI - Introduction to Visualforce
Chapter 09
Ajax control asp.net
Asp.Net Ajax Component Development
C sharp and asp.net interview questions
ASP.NET Lecture 6
Custom Controls in ASP.net
User controls
11 asp.net session16
Parallelminds.web partdemo1
NET_Training.pptx
Angular - Chapter 4 - Data and Event Handling
Ad

More from Ankit Gupta (20)

PPT
Biometricstechnology in iot and machine learning
PDF
Week2 cloud computing week2
PDF
Week 8 lecture material
PDF
Week 4 lecture material cc (1)
PDF
Week 3 lecture material cc
PDF
Week 1 lecture material cc
PDF
Mod05lec25(resource mgmt ii)
PDF
Mod05lec24(resource mgmt i)
PDF
Mod05lec23(map reduce tutorial)
PDF
Mod05lec22(cloudonomics tutorial)
PDF
Mod05lec21(sla tutorial)
PDF
Lecture29 cc-security4
PDF
Lecture28 cc-security3
PDF
Lecture27 cc-security2
PDF
Lecture26 cc-security1
PDF
Lecture 30 cloud mktplace
PDF
Week 7 lecture material
PDF
Gurukul Cse cbcs-2015-16
PDF
Microprocessor full hand made notes
PPTX
Transfer Leaning Using Pytorch synopsis Minor project pptx
Biometricstechnology in iot and machine learning
Week2 cloud computing week2
Week 8 lecture material
Week 4 lecture material cc (1)
Week 3 lecture material cc
Week 1 lecture material cc
Mod05lec25(resource mgmt ii)
Mod05lec24(resource mgmt i)
Mod05lec23(map reduce tutorial)
Mod05lec22(cloudonomics tutorial)
Mod05lec21(sla tutorial)
Lecture29 cc-security4
Lecture28 cc-security3
Lecture27 cc-security2
Lecture26 cc-security1
Lecture 30 cloud mktplace
Week 7 lecture material
Gurukul Cse cbcs-2015-16
Microprocessor full hand made notes
Transfer Leaning Using Pytorch synopsis Minor project pptx

Recently uploaded (20)

PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Pharma ospi slides which help in ospi learning
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
RMMM.pdf make it easy to upload and study
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Lesson notes of climatology university.
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Trump Administration's workforce development strategy
O5-L3 Freight Transport Ops (International) V1.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Pharma ospi slides which help in ospi learning
human mycosis Human fungal infections are called human mycosis..pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
RMMM.pdf make it easy to upload and study
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Lesson notes of climatology university.
Orientation - ARALprogram of Deped to the Parents.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Yogi Goddess Pres Conference Studio Updates
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
STATICS OF THE RIGID BODIES Hibbelers.pdf
Weekly quiz Compilation Jan -July 25.pdf
Trump Administration's workforce development strategy

Asp PPT (.NET )

  • 7. Design view-Adding a button and a textbox
  • 11. Using the Validation control • Using the RequiredFieldValidator Control • In this example, we are adding two RequiredFieldValidator controls on a Web page for validating twoTextBox controls. The RequiredFieldValidator controls ensure that the two TextBox controls are not kept empty by the user at runtime.
  • 13. Default.aspx • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" • Inherits="_Default" %> • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" • "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> • <html xmlns="http://www.w3.org/1999/xhtml"> • <head runat="server"> • <title>RequiredFieldValidator Control Example</title> • </head> • <body> • <form id="form1" runat="server"> • <div> • <asp:Label ID="Label1" runat="server" • Text="RequiredField Validator Control Example" Font-Bold="True" • Font-Size="Medium" Font-Underline="True"></asp:Label> • <br /> • <br /> • <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="Small" • Text="User name:"></asp:Label> • &nbsp;&nbsp; • <asp:TextBox ID="TextBox1" runat="server" Height="22px" • Width="175px"></asp:TextBox> • <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" • ControlToValidate="TextBox1" ErrorMessage="User name can not be • empty"></asp:RequiredFieldValidator> • <br /> • <br /> • erver"
  • 14. Cont.. • <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Small" • Text="Password:"></asp:Label> • &nbsp;&nbsp;&nbsp;&nbsp; • <asp:TextBox ID="TextBox2" runat="server" Height="22px" TextMode="Password" • Width="175px"></asp:TextBox> • <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="s • ControlToValidate="TextBox2" ErrorMessage="Password can not be • empty"></asp:RequiredFieldValidator> • <br /> • <br /> • <br /> • &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; • &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; • &nbsp;&nbsp;&nbsp;&nbsp; • <asp:Button ID="Button1" runat="server" BackColor="Black" Font-Bold="True" • Font-Size="Medium" ForeColor="White" Text="Submit" /> • </div> • </form> • </body> • </html>
  • 15. Using the RangeValidator Control: (Regular expression for date (^(19|20)dd([- /.])(0[1-9]|1[012])2(0[1-9]|[12][0- 9]|3[01])$)
  • 17. Using the RegularExpressionValidator Control • In this example, we are taking two RegularExpressionValidator controls on a Web page for validating two TextBox controls. It ensures that the data (URL and email address) entered in both the TextBox controls is valid
  • 20. Using the CompareValidator Control • In this example, we take a CompareValidator control on a Web page, which validates the third TextBox control. It ensures that the data (password) entered in the third TextBox control is exactly the same as the data • (password) entered in the second TextBox control.
  • 22. user interface and functionality. Properties Description Caption Gets or sets the caption for the calendar control. CaptionAlign Gets or sets the alignment for the caption. CellPadding Gets or sets the number of spaces between the data and the Cell border. CellSpacing Gets or sets the space between cells. DayHeaderStyle Gets the style properties for the section that displays the day of the week. DayNameFormat Gets or sets format of days of the week. DayStyle Gets the style properties for the days in the displayed month. FirstDayOfWeek Gets or sets the day of week to display in the first column.
  • 23. Cont.. NextMonthText Gets or sets the day of week to display in the first column. NextPrevFormat Gets or sets the text for next month navigation control .The default value is > . OtherMonthDayStyle Gets or sets the format of the next and previous month navigation control. PrevMonthText Gets the style properties for the days on the Calendar control that are not in the displayed month. SelectedDate Gets or sets the text for previous month navigation control. The default value is < . ShowGridLines Gets or sets the value indicating whether the gridlines would be shown.
  • 24. Events Events Description SelectionChan ged It is raised when a day, a week or an entire month is selected. DayRender t is raised when each data cell of the calendar control is rendered. VisibleMonth Changed It is raised when user changes a month.
  • 26. Default.aspx* • <%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="rich_controls._Default" %> • <asp:Content ID="Content1" runat="server" contentplaceholderid="MainContent"> • <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar> • <div _designerregion="0"> • </div> • <p>Todays date is: • <asp:Label ID="lblday" runat="server"></asp:Label> • </p> • <p>Your Birday is: • <asp:Label ID="lblbday" runat="server"></asp:Label> • </p> • </asp:Content>
  • 27. Double click on the calendar • Public Class _Default • Inherits Page • Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load • End Sub • Protected Sub Calendar1_SelectionChanged(sender As Object, e As EventArgs) Handles Calendar1.SelectionChanged • lblday.Text = Calendar1.TodaysDate.ToShortDateString() • lblbday.Text = Calendar1.SelectedDate.ToShortDateString() • End Sub • End Class
  • 29. Creating custom controls with user Controls • ASP.NET allows the users to create controls. These user defined controls are categorized into: • User controls • Custom controls
  • 30. User Conrols • User controls behaves like miniature ASP.NETpages or web forms, which could be used by many other pages. These are derived from the system.Web.UI.UserControl class. These controls have the following characteristics • They have an .ascx extension. • They may not contain any <html>, <body>,or <form> tags. • They have a Control directive instead of a Page directive. • To understand the concept, let us create a simple user control, which will work as footer for the web pages. To create and use the user control, take the following steps:
  • 31. Steps • Create a new web application. • Right click on the project folder on the Solution Explorer and choose Add New Item. • Select Web User Control from the Add New Item dialog box and name it u1.ascx. Initially, the footer.ascx contains only a Control directive. • <%@ Control Language="C#" AutoEventWireup="true" • CodeBehind=“u1.ascx.cs" Inherits="customcontroldemo.footer" %>
  • 33. Register user control • <%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication12._Default" %> • <%@ Register Src="~/u1.ascx" TagName="u" TagPrefix="ut" %>
  • 34. Add a form to the project and use this control • <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication12.WebForm1" %> • <%@ Register Src="~/u1.ascx" TagName="u" TagPrefix="ut1" %> • <!DOCTYPE html> • <html xmlns="http://www.w3.org/1999/xhtml"> • <head runat="server"> • <title></title> • </head> • <body> • <form id="form1" runat="server"> • <div> • • </div> • <ut1:u ID="footer1" runat="server" /> • </form> • </body> • </html>
  • 36. Custom Control • 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: • By deriving a custom control from an existing control • By composing a new custom control combing two or more existing controls • By deriving from the base control class To understand the concept, let us create a custom control, which will simply render a text message on the browser. If you want to change the functionality of existing controls, such as a button or label, you can directly derive the new class with these existing classes and can change their default behavior. In brief, the Control class provides the basic functionality by which you can place it in the control tree for a Page class. The WebControl class adds the functionality to the base Control class for displaying visual content on the client computer. For example, you can use the WebControl class to control the look and styles through properties like font, color, and height.
  • 37. 1. Create an empty ASP.NET web form application
  • 38. 2. Right click on the web application and add ASP.NET server control:wc (name of the custom control) Imports System Imports System.Collections.Generic Imports System.Data Imports System.ComponentModel Imports System.Text Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls <DefaultProperty("Text"), ToolboxData("<{0}:wc runat=server></{0}:wc>")> _ Public Class wc Inherits WebControl <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String Get Dim s As String = CStr(ViewState("Text")) If s Is Nothing Then Return String.Empty Else Return s End If End Get Set(ByVal Value As String) ViewState("Text") = Value End Set End Property Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter) writer.Write("hello world from custom controls") End Sub End Class
  • 39. Build the application • Open a new or existing web form where you can use the custom control.
  • 40. Web form2.aspx file • <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication15.WebForm2" %> • <%@ Register assembly="WebApplication15" namespace="WebApplication15" tagprefix="cc1" %> • <!DOCTYPE html> • <html xmlns="http://www.w3.org/1999/xhtml"> • <head runat="server"> • <title></title> • </head> • <body> • <form id="form1" runat="server"> • <div> • • <cc1:wc ID="wc1" runat="server" /> • • </div> • </form> • </body> • </html>