December 5, 2014 06:53 by
Peter
In this article, we want to talk about How to to develop a simple Example of text box control with ASP.NET 5. Once we enter data during this text box control we want to the length (re-size height and width) of text box. Text box is an ASP.NET web control, use for obtaining input by user as similar to the login web site we see username and password Textbox exactly in which we enter username and password. Inside the Toolbox we obtain a textbox only drag and drop it on ASP.NET web site and then it is automatically create our html code. We think about a text box and attempt to Auto re-size it once we enter value in text box.
And this is the example code that I used:
JavaScript function for resize ASP.NET control
And here is the Text Box auto resize function.
function resizemultilineTextBox(txt) {
txt.style.height = "1px";
txt.style.height = (1 + txt.scrollHeight) + "px";
}
Asp.net web page code with Textbox:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Autoresizetextboxcontrol.aspx.cs" Inherits="Autoresizetextboxcontrol" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script>
function resizemultilineTextBox(txt) {
txt.style.height = "1px";
txt.style.height = (1 + txt.scrollHeight) + "px";
}
</script>
<style type="text/css">
.style1
{
color: #990000;
text-decoration: underline;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<form id="form2" runat="server">
<div align="center" style="height: 123px; background-color: #6699FF">
<h1 class="style1">Auto Resize ASP.NET TextBox Control</h1>
<table style="width: 494px">
<tr>
<td>Enter Text Here: </td>
<td>
<asp:TextBox ID="txtDescription" runat="server"
onkeyup="resizemultilineTextBox(this)" TextMode="MultiLine" Width="212px">
</asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>