<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="TitledTextBoxTest" %>
<%@ Register TagPrefix="apress" Namespace="CustomServerControlsLibrary"
Assembly="CustomServerControls" %>
Untitled Page
File: CustomServerControls.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CustomServerControlsLibrary
{
[Designer(typeof(TitledTextBoxDesigner))]
public class TitledTextBox : CompositeControl
{
public TitledTextBox() : base()
{
Title = "";
Text = "";
}
protected Label label;
protected TextBox textBox;
public string Title
{
get {return (string)ViewState["Title"];}
set {ViewState["Title"] = value;}
}
public string Text
{
get {return (string)ViewState["Text"];}
set {ViewState["Text"] = value;}
}
protected override void CreateChildControls()
{
label = new Label();
label.EnableViewState = false;
label.Text = Title;
Controls.Add(label);
Controls.Add(new LiteralControl(" "));
textBox = new TextBox();
textBox.EnableViewState = false;
textBox.Text = Text;
textBox.TextChanged += new EventHandler(OnTextChanged);
Controls.Add(textBox);
}
public event EventHandler TextChanged;
protected virtual void OnTextChanged(object sender, EventArgs e)
{
if (TextChanged != null)
TextChanged(this, e);
}
}
}
public partial class TitledTextBoxTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}