AddAttribute("type","text");
writer.AddAttribute("name",UniqueID);
writer.AddAttribute("value",Text);
base.AddAttributesToRender(writer);
}
Listing 4-2 shows the full code for the TextBox control.
Listing 4-2. The TextBox Control
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using System.ComponentModel;
namespace ControlsBook2Lib.Ch04
{
[ToolboxData("<{0}:textbox runat=server>{0}:textbox>"),
DefaultProperty("Text")]
public class Textbox : WebControl, IPostBackDataHandler
{
public Textbox()
: base(HtmlTextWriterTag.Input)
{
}
public virtual string Text
{
get
138 CHAPTER 4 ?– T HE WEBCONTROL BASE CLASS AND CONTROL S TYLES
{
object text = ViewState["Text"];
if (text == null)
return string.Empty;
else
return (string)text;
}
set
{
ViewState["Text"] = value;
}
}
public bool LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
string postedValue = postCollection[postDataKey];
if (!Text.Equals(postedValue))
{
Text = postedValue;
return true;
}
else
return false;
}
public void RaisePostDataChangedEvent()
{
OnTextChanged(EventArgs.Empty);
}
private static readonly object TextChangedKey = new object();
public event EventHandler TextChanged
{
add
{
Events.
Pages:
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231