RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Working with ASP.NET User Controls

User controls provide a way to reuse common user interface functionality across ASP.NET web applications. For example, you might create user control that encapsulates a login screen. You could then add the user control to any Web Form that requires the login screen functionality. For more information about user controls, click the link at the end of this topic.

To create an ASP.NET user control

  1. Open an ASP.NET application.
  2. Choose FileNewOtherDelphi for .NET ProjectsNew ASP.NET Files and double-click on ASP.NET User Control. A new .ascx file is added to the Project Manager and the empty page is displayed in the Designer. Optionally, rename the .ascx file by right-clicking it in the Project Manager and choosing Rename. Any associated files, such as the .pas or .resx files, are also renamed.
  3. Design the page by adding controls, setting properties, and adding code to the code-behind .pas file as needed.
  4. Save and compile the project.

To add an ASP.NET user control to a Web Form

  1. Open the Web Form to which you want to add the user control. Make sure the Designer is displayed.
  2. Choose InsertInsert User Control to display the Insert User Control dialog box.
  3. Select a user control from the drop-down list or use the Browse button to navigate to a user control file (.ascx).
  4. Click OK to add the user control to the Web Form.
  5. Optionally, in the Object Inspector, provide a descriptive name for the user control button with the Id property.
  6. Save and compile the project.
The Web Form is displayed in the browser and the user control button is replaced with its encapsulated controls.
Tip: The runtime appearance of the user control depends on the appearance of the encapsulated page and controls, not the position of the user control button. If you are adding multiple user controls to a page, run the application to ensure that the controls do not overlap each other.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!