However, in this chapter, we choose the route of separate classes so that we
can more clearly isolate the two TextBox control examples and highlight the different design
decisions embodied in them.
CHAPTER 5 ?– SERVER CONTROL EVEN TS 201
Replacing the event declaration is the easiest part. The control starts with an EventHandler
delegate but is changed to take a TextChangedEventHandler delegate:
public event TextChangedEventHandler TextChanged;
The second change is the replacement of the OnTextChanged event invocation method to
take TextChangedEventArgs as the single parameter to the method, as shown in the following
code. This is one of the reasons for having the On-prefixed methods in controls as an abstraction
layer. It makes it a simpler code change to augment or replace the event mechanism.
protected virtual void OnTextChanged(TextChangedEventArgs tce)
{
if (TextChanged != null)
TextChanged(this, tce);
}
The next step is to add logic to track the before and after values. A private string field named
oldText is added to the class and is given its value inside LoadPostData. This gives us a chance
to load TextChangedEventArgs properly when we raise the event. Here is a snippet of the code
change from LoadPostData that does the work:
if (!Text.
Pages:
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302