Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Resize multiline asp.net textbox dynamically based on text using javascript

Feb 25, 2011
Introduction:

In this article I will explain how to change or increase the textbox height dynamically using asp.net

Description:

I have one textbox my requirement is if user enters text in texbox that height of textbox needs to be adjusting with text for that I have written one JavaScript function to adjust textbox height here one more point is we need to set the
TextMode="MultiLine" property for textbox to adjust textbox height 
 
Now design your aspx page like this



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Automatic Resize TextBox</title>
<script type="text/javascript">
function setHeight(txtdesc) {
txtdesc.style.height = txtdesc.scrollHeight + "px";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtDesc" runat= "server" TextMode="MultiLine"  onkeyup="setHeight(this);" onkeydown="setHeight(this);" />
</form>
</body>
</html>
 


Demo


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

9 comments :

Roopa said...

Hey thanks to u..it was of gr8 help :)

Tushar said...

It is really great....beautiful solution.......Keep it up...Thanks....

Anonymous said...

Thanks - works great in IE but Firefox keeps making the box bigger even when removing lines

Anonymous said...

Any solution for this example so that it can work in other browsers than IE?Anyway thanks for the article

Anonymous said...

A VERY BIG THANK!!!!!!!!!!!!!!!!!!!! YOU!!!!!!!!!!!!!!!!!!!!

willzinhow said...

You are a genius, thank you so much!

ram charan said...

tnq so much........
i have to set text box lengt nly 7 character how can i

Ashish said...

its not working

Veersh Dachepally said...

Hai this is not Working....While Im removing my characters size is going to bib

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.