ASP.NET Custom Server Controls: Cute ASP.NET TextBox Control - Is it cute? How can we make it cute?
(Page 6 of 6 )
No, it is not at all cute until now. How do we implement cuteness? Just imagine, I would like to have the background color of “MyTextBox” to be automatically changed to a color when it receives the user's focus (or cursor) and back to the color white after losing the focus. Is this not cute? Now we shall see how to implement this. Modify your “render” method, which looks like this:
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
MyBase.AddAttributesToRender(output)
output.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID)
output.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID)
output.AddAttribute(HtmlTextWriterAttribute.Type, "text")
output.AddAttribute(HtmlTextWriterAttribute.Value, Text)
output.AddAttribute("onfocus", "event.srcElement.style.
backgroundColor='beige';")
output.AddAttribute("onblur", "event.srcElement.style.
backgroundColor='white';")
output.RenderBeginTag(HtmlTextWriterTag.Input)
output.RenderEndTag()
End Sub
Within the Render method (above), we are just adding two more attributes to enable our control’s cuteness.
This control has been developed just to initiate you and show the power of custom controls to control everything right from beginning until the end, including client-side JavaDcript emission. I didn’t quite implement all of the features of the original ASP.NET Textbox control (as it would take a series of articles). You just need to learn a few more interfaces and methods to implement all the original features, along with your own features.
I leave it to the developers for further enhancing the same control. The areas for improving the same control would include eventing, better JavaScript for validation, data-binding, implementing styles, and so forth. Good luck.
Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |