Custom Search
Logiclabz
  • Home
  • Asp.Net
  • Creating Custom Web Server Control in Asp.Net 2.0 with C#

Creating Custom Web Server Control in Asp.Net 2.0 with C#

  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace Project.Controls
 {
     [DefaultProperty("Text")]
     [ToolboxData("<{0}:ControlName runat=server>")]
     [ParseChildren(false)]

     public class ControlName : WebControl
       {

         protected string _Caption = "";
         protected string _Text = "";

         [Bindable(true)]
         [Category("Appearance")]
         [DefaultValue("")]
         [Localizable(true)]
         public string Caption // Public properties
         {
            get { return _Caption; }
            set { _Caption = value; }
         }

         [Bindable(true)]
         [Category("Appearance")]
         [DefaultValue("")]
         [Localizable(true)]
         public string Text // Public properties
         {
            get { return _Text; }
            set { _Text = value; }
         }
         public ControlName()
         {
            //Statement to run while initialize of control
         }
         public override void RenderControl(HtmlTextWriter writer)
         {
           RenderContents(writer);
         }
         protected override void RenderContents(HtmlTextWriter output)
         {
            //Codes for rendering html to be written here
           output.WriteBeginTag ("div");
           output.WriteAttribute("class",_Caption);
           RenderChildren(output); // Render Child Control is Exists
           output.WriteEndTag("div");
         }
      }
   }



  


Leave a reply




Do you like this post?