Click here to Skip to main content
15,895,667 members
Articles / Web Development / HTML

Introduction to Developing a Custom Web Control.

Rate me:
Please Sign up or sign in to vote.
3.90/5 (7 votes)
14 Feb 2005CPOL2 min read 54.1K   862   29  
This article explains the development of a custom web control using C#.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		
		protected string[] msgtype= new string[]{"INFORMATION","WARNING","ERROR"};
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.RadioButton RadioButton1;
		protected System.Web.UI.WebControls.RadioButton RadioButton2;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
		protected System.Web.UI.WebControls.RadioButton Radiobutton3;
		protected System.Web.UI.WebControls.RadioButton Radiobutton4;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button3;
		protected Genesys.InformationLine InformationLine2;
		protected System.Web.UI.WebControls.Label Label3;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if(!Page.IsPostBack)
				Page.DataBind();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e) {
			InformationLine2.Text = TextBox1.Text;
			InformationLine2.Details = TextBox2.Text;
			if(RadioButton1.Checked){
				InformationLine2.IsDebug = true;
			}else if(RadioButton2.Checked){
				InformationLine2.IsDebug = false;
			}
			if(DropDownList1.SelectedIndex == 0){
				InformationLine2.MsgType = Genesys.InformationLine.MessageType.INFORMATION;
			}else if(DropDownList1.SelectedIndex == 1){
				InformationLine2.MsgType = Genesys.InformationLine.MessageType.WARNING;
			}else{
				InformationLine2.MsgType = Genesys.InformationLine.MessageType.ERROR;
			}
			InformationLine2.Enabled = true;
		}

		private void Button2_Click(object sender, System.EventArgs e) {
			if(Radiobutton4.Checked){
				InformationLine2.IsDebug = true;
			}else if(Radiobutton3.Checked){
				InformationLine2.IsDebug = false;
			}
			int i = 0;
			try{
				i = 2/i;
			}catch(DivideByZeroException ex){
				InformationLine2.Exception = ex;
			}
			InformationLine2.Enabled = true;
		}

		private void Button3_Click(object sender, System.EventArgs e) {
			InformationLine2.IsDebug = false;
			InformationLine2.Enabled = false;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager Capgemini
United States United States
I have been working in software industry for the past 11 years, though i am trained to be a pharmacist. Enjoy working on complex and new technologies. Also cleared my SCJP and MCP certification examinations.

Comments and Discussions