Building ASP.NET Server Controls-CustomEventTextbox.cs
2012-05-13 23:22
525 查看
// Title: Building ASP.NET Server Controls
//
// Chapter: 5 - Event-based Programming
// File: CustomEventTextbox.cs
// Written by: Dale Michalk and Rob Cameron
//
// Copyright ?2003, Apress L.P.
using System;
using System.Web;
using System.Web.UI;
using System.Collections.Specialized;
using System.ComponentModel;
namespace ControlsBookLib.Ch05
{
[ToolboxData("<{0}:CustomEventTextbox runat=server></{0}:CustomEventTextbox>"),
DefaultProperty("Text")]
public class CustomEventTextbox : Control, IPostBackDataHandler
{
private string oldText;
public virtual string Text
{
get
{
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))
{
oldText = Text;
Text = postedValue;
return true;
}
else
return false;
}
public void RaisePostDataChangedEvent()
{
OnTextChanged(new TextChangedEventArgs(oldText, Text));
}
protected void OnTextChanged(TextChangedEventArgs tce)
{
if (TextChanged != null)
TextChanged(this, tce);
}
public event TextChangedEventHandler TextChanged;
override protected void Render(HtmlTextWriter writer)
{
base.Render(writer);
Page.VerifyRenderingInServerForm(this);
// write out the <INPUT type="text"> tag
writer.Write("<INPUT type=\"text\" name=\"");
writer.Write(this.UniqueID);
writer.Write("\" value=\"" + this.Text + "\" />");
}
}
}
//
// Chapter: 5 - Event-based Programming
// File: CustomEventTextbox.cs
// Written by: Dale Michalk and Rob Cameron
//
// Copyright ?2003, Apress L.P.
using System;
using System.Web;
using System.Web.UI;
using System.Collections.Specialized;
using System.ComponentModel;
namespace ControlsBookLib.Ch05
{
[ToolboxData("<{0}:CustomEventTextbox runat=server></{0}:CustomEventTextbox>"),
DefaultProperty("Text")]
public class CustomEventTextbox : Control, IPostBackDataHandler
{
private string oldText;
public virtual string Text
{
get
{
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))
{
oldText = Text;
Text = postedValue;
return true;
}
else
return false;
}
public void RaisePostDataChangedEvent()
{
OnTextChanged(new TextChangedEventArgs(oldText, Text));
}
protected void OnTextChanged(TextChangedEventArgs tce)
{
if (TextChanged != null)
TextChanged(this, tce);
}
public event TextChangedEventHandler TextChanged;
override protected void Render(HtmlTextWriter writer)
{
base.Render(writer);
Page.VerifyRenderingInServerForm(this);
// write out the <INPUT type="text"> tag
writer.Write("<INPUT type=\"text\" name=\"");
writer.Write(this.UniqueID);
writer.Write("\" value=\"" + this.Text + "\" />");
}
}
}
相关文章推荐
- Building ASP.NET Server Controls-Textbox.cs
- Building ASP.NET Server Controls-StatelessLabel.cs
- Building ASP.NET Server Controls-Copy of Pager.cs
- Building ASP.NET Server Controls-TextChanged.cs
- Building ASP.NET Server Controls-FancyLabel.cs
- Creating Custom ASP.NET Server Controls with Embedded JavaScript
- ASP.NET User Controls and Custom Server Controls
- Creating Custom ASP.NET Server Controls with Embedded JavaScript
- Validation Server Controls->ASP.NET CustomValidator Control
- Building ASP.NET Server Controls
- Web server Controls->ASP.NET TextBox Control
- Asp.net三层结构入门示例源码>>SQLserver/SQLHelper.cs
- ASP.NET AJAX Roadmap--Server Controls (10): UpdateProgress Control Tutorials
- asp.net textbox textchanged event not fire
- Web Server Controls->ASP.NET CheckBoxList Control
- asp.net .ashx,cs文件使用server.mappath解决方法
- asp.net .ashx,cs文件使用server.mappath解决方法
- ASP.NET AJAX Roadmap--Server Controls (11): Timer Control Overview
- Web Server Controls->ASP.NET DropDownList Control
- Web Server Controls->ASP.NET Table Control