Wednesday 15 May 2013

Automatic Scroll down in Multiline TextBox in asp.net using JavaScript.

Introduction:-


In this article , I have described how to automatic scroll down in Multiline textbox in asp.net using  JavaScript . ScrollBar will persistent when you entering data in textbox or adding data in textbox.

Design page:-

<!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 runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    window.onload = function () {
        var textarea = document.getElementById('<%=TextBox2.ClientID %>');
        textarea.scrollTop = textarea.scrollHeight;
    }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server" Text="Sample Text"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Add" OnClick="Button1_Click" />
<hr />
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Height="100"
            ontextchanged="TextBox2_TextChanged"></asp:TextBox>
    </div>
    </form>
</body>
</html>

Code Behnid Page:-

protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox2.Text += TextBox1.Text + "\n";
    }


Run the code and check output.

No comments:

Post a Comment

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