OR Control Language="c#" %> Contains code to handle its own events"> OR Control Language="c#" %> Contains code to handle its own events">
Download presentation
Presentation is loading. Please wait.
1
USER CONTROL
2
What is a User Control ? User controls simplify the reuse of code and UI components within a Web application A user control is a user-defined Web server control with an .ascx extension Contains HTML, but not the <HTML>, <BODY>, or <FORM> tags Control Language="vb" %> OR Control Language="c#" %> Contains code to handle its own events
3
Creating a User Control
Two methods for user control creation: Create a new user control using Visual Studio .NET Convert an existing ASP.NET page to a user control Host page interacts with the control using properties Host page should use flow layout Public Property pNum() As Integer Get Return Convert.ToInt32(txtNum.Text) End Get Set (ByVal value As Integer) txtNum.Text = CStr(value) End Set End Property public int pNum { get return Convert.ToInt32(txtNum.Text); } set txtNum.Text = Convert.ToString(value);
4
Adding a User Control Use Register directive to include a user control in an ASP.NET Page Register TagPrefix="demo" TagName="validNum" Src="numberbox.ascx" %> Insert the user control in a Web Form <demo:validNum id="num1" runat="server"/> Use Get and Set properties of the user control num1.pNum = 5 'uses Set x = num1.pNum 'uses Get OR num1.pNum = 5; //uses Set x = num1.pNum; //uses Get
5
Why Use User Controls? Application A Application B
Reuse user interface and code Application A Control1.ascx Application B Page3.aspx Page1.aspx Page2.aspx
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.