Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert an ASP.NET User control to Web/Composite Control?

Is there a simple process to convert an user control to a web/composite control?

like image 997
burnt1ce Avatar asked Feb 10 '10 21:02

burnt1ce


People also ask

What are three categories of Web controls?

Web controls fall into five categories: display, input, selection, validation, and special purpose.

What is user control in ASP.NET with example?

The following example shows an ASP.NET Web page that contains a user control. The user control is in the file Spinner. ascx in the Controls folder. In the page, the control is registered to use the prefix uc and the tag name Spinner. The user control properties MinValue and MaxValue are set declaratively.

What is Web Control explain different types of web control?

Web controls are basically HTML elements wrapped under easy to use scripting tags of ASP+ and provide rich functionality in your FORMs or pages. Web controls range from simple text box to advance girds and lists.

What is Web FORMs server control?

Features of ASP.NET Web Forms. Server Controls- ASP.NET Web server controls are objects on ASP.NET Web pages that run when the page is requested and that render markup to the browser. Many Web server controls are similar to familiar HTML elements, such as buttons and text boxes.


1 Answers

There's no automatic process, no. Here's the (general) steps to follow though:

  1. Create a webcontrol class. Make it inherit from Panel if you want to take the easy way, or else override the Render() method if you want to generate your HTML the long, verbose way.

  2. Duplicate the layout of the user control by adding html literals and other controls into the Controls collection during Init() or in the constructor for your control class. If you chose to override Render(), you'll need to recursively render the controls.

  3. Copy event handling code-behind from your usercontrol into your class, and wireup the event handlers.

  4. Deal with javascripts/css. You can embed them into your assembly as web resources, or register them as regular includes using ClientScriptManager or ScriptManager.

like image 177
womp Avatar answered Sep 20 '22 04:09

womp