May 2010 - Posts

Expandable or Auto-Resize TextBox Height

Recently, I was asked to prepare a Facebook like expandable textbox in a ASP.NET web application, where user can input text and the textbox can be re-sized (more specifically the height) dynamically.

I searched for a while and found quite a lot of solutions that use jQuery (example). However, I was looking for something more intrinsic and simple, and finally I found another script on a forum that just use few lines of JavaScript codes:

1. Control declaration:

<asp:TextBox ID="txtMsg" runat="server"  TextMode="MultiLine" style="overflow:hidden" onkeyup="AutoExpand(this, event)" Rows="2" />

2. JavaScript function:

function AutoExpand(txtBox, event)
{
    if (event.keyCode == "13" || event.keyCode == "8") {
        var therows = 0
        var thetext = document.getElementById(txtBox.id).value;
        var newtext = thetext.split("\n");
        therows += newtext.length

        document.getElementById(txtBox.id).rows = therows;
        return false;
    }
}

That's it. Just put the script above in a script file and then re-use it for any buttons in the whole application.

Posted by Colt | 22 comment(s)
Filed under:

ASP.NET Tooltips Extender Control

Tooltips is always a good usability practice to display descripitve and meaningful message on UI, which provide guidance and extra information to users visually. However, I cannot find this kind of handy "control" in the latest version (40412) of the AJAX control toolkit. (Feature request?)

The traditional HTML "title" or "tooltips" tag of control cannot make the users (nor even developers) happy, so I searched and found this Tooltip Extender control today. It is nice and handy for developers, and it has HTML editing capabilities inside the tooltips panel.

I downloaded the source and re-compiled it against the latest version of AJAX control toolkit library, then add it to my current web project. So I can add tooltips information easily now. Nice! :)

For example,

Posted by Colt | 4 comment(s)
More Posts