Welcome to our home page! File Name: HomePage.aspx"> Welcome to our home page! File Name: HomePage.aspx">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Custom Controls with User Controls. Including Standard Content with User Controls Global Super Company Global Super Company We mean business!

Similar presentations


Presentation on theme: "Creating Custom Controls with User Controls. Including Standard Content with User Controls Global Super Company Global Super Company We mean business!"— Presentation transcript:

1 Creating Custom Controls with User Controls

2 Including Standard Content with User Controls Global Super Company Global Super Company We mean business! File name: SimpleHeader.ascx

3 Including Standard Content with User Controls <%@ Register TagPrefix="SuperCompany" TagName="Header" Src="SimpleHeader.ascx" %> <Supercompany:Header ID="ctlHeader" Runat="Server" /> Welcome to our home page! File Name: HomePage.aspx

4 Including Standard Content with User Controls ► TagPrefix  The alias to associate with the user control ’ s namespace ► TagName  The alias to associate with the user control ’ s class ► Src  The virtual path to the file containing the user control

5 Including Standard Content with User Controls <table width="90%" cellpadding="2" cellspacing="0" border="1" bordercolor="red"> File Name: Divider.ascx

6 Including Standard Content with User Controls UserControlsDivider.aspx Here is some text... Here is some more text... Yet some more text... File Name: UserControlsDivider.aspx

7 Exposing Properties and Methods in User Controls Public PageTitle As String = "Global Super Company" Global Super Company We mean business! File Name: HeaderTitle.ascx

8 Exposing Properties and Methods in User Controls <%@ Register TagPrefix="SuperCompany" TagName="Header" Src="HeaderTitle.ascx" %> <Supercompany:Header ID="ctlHeader" PageTitle="The Home Page" Runat="Server" /> Welcome to our home page! File Name: HomePageTitle.aspx

9 Exposing Properties and Methods in User Controls Public Word As String Sub Repeat( intNumTimes As Integer ) Dim intCounter As Integer For intCounter = 0 to intNumTimes - 1 Response.Write( Word ) Next End Sub File Name: WordRepeater.ascx

10 Exposing Properties and Methods in User Controls <%@ Register TagPrefix="SuperCompany" TagName="WordRepeater" Src="WordRepeater.ascx" %> Sub Page_Load myWordRepeater.Repeat( 50 ) End Sub DisplayWordRepeater.aspx <SuperCompany:WordRepeater ID="myWordRepeater “ Word="Hello" Runat="Server" /> File Name: DisplayWordRepeater.aspx

11 Exposing Web Controls in User Control Street Address: City: State: ZIP: File Name: Address.ascx

12 Exposing Web Controls in User Control <%@ Register TagPrefix="SuperCompany" TagName="Address" Src="Address.ascx" %> DisplayAddress.aspx Billing Address Shipping Address File Name: DiaplayAddress.aspx

13 Exposing Web Controls in User Control Public Property Street As String Get Return txtStreet.Text End Get Set txtStreet.Text = Value End Set End Property Public Property City As String Get Return txtCity.Text End Get Set txtCity.Text = Value End Set End Property Public Property State As String Get Return txtState.Text End Get Set txtState.Text = Value End Set End Property Public Property ZIP As String Get Return txtZIP.Text End Get Set txtZIP.Text = Value End Set End Property Street Address: <asp:TextBox ID="txtStreet" Runat="Server" /> City: <asp:TextBox ID="txtCity" Runat="Server" /> State: <asp:TextBox ID="txtState" Runat="Server" /> ZIP: <asp:TextBox ID="txtZIP" Runat="Server" /> File Name: AddressProperties.ascx

14 Exposing Web Controls in User Control <%@ Register TagPrefix="SuperCompany" TagName="Address" Src="AddressProperties.ascx" %> Sub Button_Click( s As Object, e As EventArgs ) lblOutput.Text = " You entered the following values: " lblOutput.Text &= " Billing Address: " lblOutput.Text &= " Street: " & ctlBillingAddress.Street lblOutput.Text &= " City: " & ctlBillingAddress.City lblOutput.Text &= " State: " & ctlBillingAddress.State lblOutput.Text &= " ZIP: " & ctlBillingAddress.ZIP lblOutput.Text &= " " lblOutput.Text &= " Billing Address: " lblOutput.Text &= " Street: " & ctlShippingAddress.Street lblOutput.Text &= " City: " & ctlShippingAddress.City lblOutput.Text &= " State: " & ctlShippingAddress.State lblOutput.Text &= " ZIP: " & ctlShippingAddress.ZIP End Sub DisplayAddressProperties.aspx Billing Address <SuperCompany:Address ID="ctlBillingAddress" Runat="Server" /> Shipping Address <SuperCompany:Address ID="ctlShippingAddress" Runat="Server" /> <asp:Button Text="Submit" OnClick="Button_Click" Runat="Server" /> <asp:Label ID="lblOutput" Runat="Server" /> File Name: DiaplayAddressProperties.aspx

15 Exposing Events in User Control Sub Page_Load Dim RanNum As New Random Select Case RanNum.Next( 3 ) Case 0 lblQuote.Text = "A penny saved is a penny earned" Case 1 lblQuote.Text = "Look before you leap" Case 2 lblQuote.Text = "He who hesitates is lost" End Select End Sub <asp:Label id="lblQuote" Runat="Server" /> File Name: ControlEvents.ascx

16 Exposing Events in User Control <%@ Register TagPrefix="SuperCompany" TagName="Quote" Src="ControlEvents.ascx" %> <SuperCompany:Quote Runat="Server" /> File Name: DisplayControlEvents.aspx


Download ppt "Creating Custom Controls with User Controls. Including Standard Content with User Controls Global Super Company Global Super Company We mean business!"

Similar presentations


Ads by Google