Introduction: In this article we will explore how to create an autoscroll for a multiline textbox using jQuery. Further inside the page we have to take the two aspx controls named as textbox and the other one is the button. In this article we will see that a textbox having multiline text will scroll automatically on clicking the button control. Let see that whenever we will click on the Button the text inside the multiline textbox will scroll downwards and further clicking again on the button it will back to it's position. Whatever we are using inside this article will be described briefly below. The following are the steps which you have to follow to accomplish your task:
Step 1: Firstly we have to create a Web Application.
- Go to Visual Studio 2010
- Create the Web Application
- Click OK.
Step 2: Secondly you have to add a new page to the website
- Go to the Solution Explorer
- Right Click on the Project name
- Select add new item
- Add new web page and give it a name
- Click OK


Step 3: In this step we have to place both the aspx control named as textbox with multiline and a button control let see from where you have to add these controls which is given below:

Step 4: In this step we are going to see
that see from where the js reference will be added to the source page of the
default2.aspx page.
Step 5: Now we are going to write the script code which will be inside either on the head section or in the body section it will depend upon you which way you like most to placed it.
![]()
Step 6: In this step we have to see that how we will apply jQuery code to the aspx control we will see the HTML code generated by the browser let see the code given below:
Browser Code: In this code you will see
that whenever we run the aspx control on the browser it will run the aspx
control according their compatibility code which have been write the aspx
textbox as a textarea and aspx button as a input type button so according these
compatibility of browser we have to write the jQuery code which we will write in
the next step 7. The code whioch is given below is the code of browser
<body>
<form
method="post"
action="Default3.aspx"
id="form1">
<div
class="aspNetHidden">
<input
type="hidden"
name="__VIEWSTATE"
id="__VIEWSTATE"
value="/wEPDwUKMTkwNjc4NTIwMWRkZgGbSRlPula4D5KoUo+QjPJDgwap+zHLCTWwK27B+8U="
/>
</div>
<div
class="aspNetHidden">
<input
type="hidden"
name="__EVENTVALIDATION"
id="__EVENTVALIDATION"
value="/wEWAwL/zuDdCQKShty0BQKSotaIC0EGc18QfpfF2WoZ9sd5eiLrf72eJQ9UIU8VrZe4+AEc"
/>
</div>
<div
class="smallDiv"
style="background-color:
#006666; font-family: 'Comic Sans MS'; font-size: xx-large; color: #FFFFFF;">
<h2
style="font-family:
'Comic Sans MS'; font-size: xx-large; font-weight: normal; color: #800000;
background-color: #808080">
Click on Button to Scroll downwards and upwards</h2>
<br
/><br
/>
<textarea
name="txt1"
rows="5"
cols="20"
id="txt1"
style="width:278px;height:142px;font-size:Large;font-family:Comic
Sans MS;color:#660033;border-width:5px;border-style:Groove;border-color:#FFFF66;background-color:#CCFFCC;">
Hi to all Hi to all Hi to all Hi to all
Amit Maheshwari MCN Solutions Mindcracker Network
Hiiiiii Hiiiiiii Hiiiiii Hiiiiiiiiiiiii
Welcome to all Welcome to all Welcome to all
Welcomezzzzzzzz Welcomezzzzzzzzzzz Welcomezzzzzzzz</textarea>
<br
/>
<input
type="submit"
name="btn1"
value="Scroll"
id="btn1"
style="color:#993333;background-color:#FFFFCC;border-color:Yellow;border-width:5px;border-style:Groove;font-family:Comic
Sans MS;font-size:Large;" />
<br
/>
Tip: Whenever we click on the button the text will be scrolled both
downwards and upwards.
</div>
</form>
</body>
Step 7: In this step we will write the jQuery code which will be inside the <script></script> tag and always placed between Head section or body section it's your choice that where you want to placed it. Let see the jQuery code which is given below:
Explanation:




Join the conversation! Your thoughts help the community grow.