1 / 6

ASP.NET User Controls

ASP.NET User Controls. User Controls . In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls using the same techniques you use for creating ASP.NET Web pages.

uzuri
Download Presentation

ASP.NET User Controls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET User Controls

  2. User Controls • In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls using the same techniques you use for creating ASP.NET Web pages. • A user control is a kind of composite control that works much like an ASP.NET Web page—you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.

  3. Overview • At times, you might need functionality in a control that is not provided by the built-in ASP.NET Web server controls. In those cases, you can create your own controls. You have two options. You can create: • User controls. User controls are containers into which you can put markup and Web server controls. You can then treat the user control as a unit and define properties and methods for it. • Custom controls. A custom control is a class that you write that derives from Control or WebControl.

  4. User Control Structure • A user controls differs from an ASP.NET Web page in these ways: • The file name extension for the user control is .ascx. • Instead of an @ Page directive, the user control contains an @ Control directive that defines configuration and other properties. • User controls cannot run as stand-alone files. Instead, you must add them to ASP.NET pages, as you would any control. • The user control does not have html, body, or form elements in it. These elements must be in the hosting page.

  5. User Control Structure • Use the same HTML elements (except the html, body, or form elements) and Web controls on a user control that you do on an ASP.NET Web page. • Add the user control to a page by registering it on the host page. • Define properties and methods for the user control. • Write code in the user control to handle the events raised by the child controls.

  6. CustomerInformation.aspx Register the user controls, add them to the page, and set the properties and methods for the user controls CollectCustomerInformation.ascx CollectCustomerInformation.ascx.cs Declare a delegate event handler which represents the method which will handle the event at the Page level, then write the method. CustomerEventArgs.cs Declare what you want to be passed in your CustomerEventArgs parameter of your CollectCustomerInformationuser control event handler. DisplayCustomerInformation.ascx DisplayCustomerInformation.ascx.cs Write a method that uses information from the CustomerEventArgs parameter to display the information from the CollectCustomerInformation user control

More Related