Ra-Ajax Samples - TextArea
The Ajax TextArea is actually one of the places in Ra-Ajax where you will immediately feel
the difference between Ra-Ajax, ASP.NET AJAX and the ASP.NET WebControls. In fact, the
Ra-Ajax TextArea is a TextBox with the TextMode property set to MultiLine. The reason why
we have chosen to build a special MultiLine TextArea control is because by using the same Control type
for both rendering <textarea and <input type="text" ASP.NET is effectively
breaking LSP or the Liskow Substitution Principle.
Try to type into the Ajax TextArea above and hit Submit.
Notice also how the above TextArea has the OnFocused Event handler set, which just makes sure that
the Text in the TextArea is selected when it gets Focus. Also notice how we set Focus to the TextArea
and select its Text when you click the Submit button. Check out this code by clicking
"Show Code" at the top right corner of this page.
About LSP
LSP or Liskow Substitution Principle means that in order for
some class A to inherit from some class B then A must be a perfect superset of B. The
classic school example of such thing is an is-a relationship. Like for example
a Rectangle and a Square.
For most people, inheriting the Square class from the
Rectangle type would seem tempting. Though since the Rectangle has properties
which the Square does not have (width and height) then this is, according
to the Liskow Substitution Principle, wrong.
Unfortunately ASP.NET, specially the WebControls namespace, is full of these violations of LSP.
One example is that the System.Web.UI.Page class inherits indirectly from the
System.Web.UI.Control class through the TemplateControl. But since Ra-Ajax tries
to be as compatible as possible with other ASP.NET Applications, there is
not really much that Ra-Ajax can do in regards to the Page LSP problem.
However what we can do, is to not violate LSP in our own inheritance hierarchy. And one example of
that is the Ajax TextArea class. In fact, you can yourself
see this problem manifested in conventional ASP.NET by dragging a System.Web.UI.WebControls.TextBox
on your page, and without changing its TextMode property, set its Rows and Columns property to some integer values.
The thing with the above example of an <input type="text" with the Rows and Columns properties
set, is that the ASP.NET runtime must either choose to ignore those properties, which is confusing for
the developer since he doesn't understand why this is not working, or the ASP.NET runtime must choose
to actually render them out to the browser, which will break (X)HTML compliance and render
undefined HTML markup to the browser.
To avoid the above LSP problem, we in Ra-Ajax have tried to do "the right thing", at least in those
places where we actually have control. And that's why you will in Ra-Ajax find a special Ajax TextArea
Control. It might be a little bit unintuitive for those who have spent a lot of time in the WebControls
namespace of ASP.NET, but after a while I think you will come to appreciate this decision.
On to Ajax TextBox