This article enlists the procedure to create and use a simple custom control that extends from System.Web.UI.Control using Visual Studio
1. Start Visual Studio. 2. Create a class library project, and give it a name, for example, CustomServerControlsLib. 3. Add a source file to the project, for example, SimpleServerControl.cs. 4. Include the reference of the System.Web namespace in the references section. 5. Check whether the following namespaces are included in the SimpleServerControl.cs file.System
System.Collections System.ComponentModel System.Data System.Web System.Web.SessionState System.Web.UI System.Web.UI.WebControls
6. Inherit the SimpleServerControls class with the Control base class. public class SimpleServerControl : Control 7. Override the Render method to write the output to the output stream.
protected override void Render(HtmlTextWriter writer) { writer.Write("Hello World from custom control"); }
Note:The HtmlTextWriter class has the functionality of writing HTML to a text stream. The Write method of the HtmlTextWriter class outputs the specified text to the HTTP response stream and is the same as the Response.Write method.
8. Compile the class library project. It will generate the DLL output.
9. Open an existing or create a new ASP.NET Web application project.
10. Add a Web Forms page where the custom control can be used.
11. Add a reference to the class library in the references section of the ASP.NET project.
12. Register the custom control on the Web Forms page.
<%@ Register TagPrefix="CC " Namespace=" CustomServerControlsLib " Assembly="CustomServerControlsLib " %>
13. To instantiate or use the custom control on the Web Forms page, add the following line of code in the
|
| Author: Venkat 04 Sep 2008 | Member Level: Silver Points : 1 |
Hi vidhya,
I cant understand ur code.So plz can u give brief explanation.Thanks
Regards Venkat
|