The Textbox Web server control can only exist within a Web form that has runat="server" within the Web forms tags, anywhere else and the compiler will fail.
It can also exist with a Panel control for mobile designers but that is not covered in this article.
The main uses of the textbox is to input new text(strings) or present the user with existing text for them to modify, the second of these operations requires something called data-binding.
The input (text you type in) can and should be processed to meet your business requirements, however some requirements are common to all businesses, namely some kind of data validation to check what’s been typed into the text boxes. In practice this can be at least two separate processes, one of which is in the clients browser and uses JavaScript and the other is on the Web server uses the .NET compatible language that generated the original page.
In practice the server side language may be C# ,C++ VB, J++ etc. Of course there are many other checks like "is this credit card number valid", which would involve a chain of processes, for now lets stay with the humble textbox control and how we might control some aspects of it by programming.
The
code with this page (in the bonus panel) shows how the same three effective tasks are performed to the textbox, in one case they are performed on the server and in the other case they are performed on the client.
Different languages are used, on the server the language is C# and on the client it's JavaScript. In both cases the code is aimed at showing you how to "get hold" of the Textbox so that you can then write some code to get it to do stuff, this example show you how you can do the same stuff but in two different places.
In each case three properties are set on the Textbox.
a) The number of characters it can hold
b) The text that will appear within the textbox
c) The colour of the area where the text is located
The Text property can also be set using the Text attribute or via the innerText property.
Any property that is set programmatically takes priority over setting the value of as an attribute.