Previously I have only really worked on applications, but now I am trying to learn web development.
For practice, I want to write an implementation of textbox watermarking – something similar to the TextBoxWatermark found in the asp.net ajax toolkit. I started by subclassing the existing textbox control, but I don’t really know where to proceed after this. I see many examples of the web that look a bit like this:
<asp:Textbox id="tb" runat="server" value="Type in the code" onfocus="if (this.value == 'Type in the code') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Type in the code';}"></asp:Textbox>
I guess I goal is to make a control that behaves something like this:
<asp:Textbox id="tbCode" runat="server" watermarkValue="Type in the code"></asp:Textbox>
With the javascript stuff somehow buried in the class definition. I don’t understand how to, for instance, register new attributes, or where to go throwing this javascript code. With my implementation, I want to be sure that when other bits of code query the textbox for its text contents, the watermark text is not returned, if that is all that is present. (something I was worried about in the first example.)
I don’t really know where to look to start doing this. Could someone explain, or point me to a tutorial that has already covered this?
This should be a good area to get started in
http://msdn.microsoft.com/en-gb/library/bb386519.aspx
You’re adding extra markup to the output, so you’re going to have to understand the control lifecycle so to know which methods to override.
Simon