Sunday, April 7, 2013

onfocus select all text OR input text select all on focus

In this post i will show how to select all text on focus of the control as shown ...

OutPut :

Aspx Coding :




<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextBoxOnFocus.aspx.cs"
    Inherits="DDL_Search_Option.TextBoxOnFocus" %>
 
<!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></title>
    <link href="Styles/OnFocusCSS.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <center>
            Focus on any control<br />
            <table style="width: 40%;">
                <tr>
                    <td>
                        <asp:TextBox ID="TextBox1" runat="server" Text="Sample Text 1" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox2" runat="server" Text="Sample Text 2" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox3" runat="server" Text="Sample Text 3" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="TextBox4" runat="server" Text="Sample Text 4" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox5" runat="server" Text=" " onfocus='this.select()' onMouseUp='return false'></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox6" runat="server" Text="Sample Text 6" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="TextBox7" runat="server" TextMode="Password" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox8" runat="server" Text="Sample Text 7" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox9" runat="server" TextMode="Password" onfocus='this.select()'
                            onMouseUp='return false'></asp:TextBox>
                    </td>
                </tr>
            </table>
            <asp:TextBox ID="TextBox10" runat="server" TextMode="MultiLine" onfocus='this.select()'
                onMouseUp='return false'></asp:TextBox>
        </center>
    </div>
    </form>
</body>
</html>



 

No comments:

Post a Comment