Monday, 1 September 2014

jQuery Code to Select All Text in TextBox on Click in Asp.Net

9/01/2014 - By Pranav Singh 0

This article will show you how you can select all or highlight the text present in a textbox or in a multiline textbox on focus or on click inside the textbox using jQuery in asp.net.


So for this article first we will create a new asp.net application and add the jQuery library reference in our asp.net page.

<script language="javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>

Now please check the below code for selecting all the text present in the textbox.

$("#<%=Control Id %>").click(function () { $(this).select(); });

So in above code we have raised event when mouse enter inside the textbox and user click on textbox. So here is the complete code.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectTextInTextBox.aspx.cs"
    Inherits="ProjectDemo_Asp.et.SelectTextInTextBox" %>

<!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>jQuery Code to Select All Text in TextBox on Click in Asp.Net</title>
    <script language="javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script language="javascript">
        $(document).ready(function () {
            /*This is for TextBox*/
            $("#<%=TextBox1.ClientID %>").click(function () { $(this).select(); });

            /*This is for multiline textbox*/
            $("#<%=TextBox2.ClientID %>").click(function () { $(this).select(); });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        TextBox:
        <asp:TextBox ID="TextBox1" runat="server" Width="180px" Text="This is a demo text from asp.net"></asp:TextBox><br />
        TextArea:<asp:TextBox ID="TextBox2" runat="server" Height="106px" TextMode="MultiLine"
            Text="This is a demo text from asp.net"></asp:TextBox>
    </div>
    </form>
</body>
</html>

So just run the code and check the output.

Tags: ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top