Home All Groups Group Topic Archive Search About
Author
5 Sep 2006 9:32 PM
TJHerman
I am using Visual Studio 2005 and writing all code-behind in VB. I'm setting
the focus of a textbox after I run some calculations. I want to additionally
select all the text in the textbox that I've set the focus to so that the
user doesn't have to manually select the text and type. Can someone give me
an example of how to do this programmatically using vb?

Author
7 Sep 2006 1:19 AM
Ken Cox [Microsoft MVP]
Hi TJ,

Here's a little code that inserts some JavaScript when the page loads to
select the text in a textbox.

If you can use Atlas, you'll find a really nice technique for creating a
Textbox watermark:

http://atlas.asp.net/atlastoolkit/TextBoxWatermark/TextBoxWatermark.aspx

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Protected Sub Page_Load _
    (ByVal sender As Object, _
    ByVal e As System.EventArgs)
        Page.SetFocus("TextBox1")
        ClientScript.RegisterStartupScript _
        (Me.GetType, "sel", _
        "document.all.TextBox1.select();", True)
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Select and Set Focus</title>
    <script  language="javascript" type="text/javascript">

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="TextBox1" runat="server">Start typing
here</asp:textbox><br />
        <br />
        <asp:button id="Button1" runat="server" text="Button" />&nbsp;</div>
    </form>
</body>
</html>

Show quoteHide quote
"TJHerman" <TJHer***@discussions.microsoft.com> wrote in message
news:1ABAF60D-8D45-42DB-AE4B-8B06D4571C96@microsoft.com...
>I am using Visual Studio 2005 and writing all code-behind in VB. I'm
>setting
> the focus of a textbox after I run some calculations. I want to
> additionally
> select all the text in the textbox that I've set the focus to so that the
> user doesn't have to manually select the text and type. Can someone give
> me
> an example of how to do this programmatically using vb?