In LoadPostData, the ViewState value of the Text property is checked against the
incoming value from postback for any differences. If there is a difference, the Text property is
changed to the new value in ViewState, and true is returned from the routine. This guarantees
that the event is raised when RaisePostDataChangedEvent is called by ASP.NET 2.0 and later
further on in the page life cycle.
public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string postedValue = postCollection[postDataKey];
if (!Text.Equals(postedValue))
{
Text = postedValue;
return true;
}
else
return false;
}
The upgrade to the RaisePostDataChangedEvent method is the addition of a single line. Instead
of being blank, it calls on our newly created OnTextChanged method to invoke the TextChanged
event. We use the static field Empty of the EventArgs class to create an instance of EventArgs for
us, as we don??™t need to customize EventArgs in this case:
public void RaisePostDataChangedEvent()
{
OnTextChanged(EventArgs.Empty);
}
The code in Listing 5-2 is full text of the control after the modifications required to add the
TextChanged event.
Listing 5-2. The Improved TextBox Control with Events Using System
using System.
Pages:
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293