Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2009, 09:22 AM
Authorized User
 
Join Date: Dec 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cursor in Text Box

Hi

I have just finished my first web site after reading Imar's book.
Everything is working fine.

Is there a way to make the cursor appear in the text box of a page without having to click in the box first.

Many thanks

Andy
 
Old February 5th, 2009, 12:54 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default You could use javascript?

Do you mean making the blinking beam appear with out clicking on it?

just focus on that textbox when the page loads?

TextBox1.focus()

is this what you are looking for or did I miss your point?
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old February 5th, 2009, 01:06 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Or....

if you want to just hover your mouse over it you can use javascript?

<asp:TextBox ID="TextBox1" runat="server" onmouseover="this.focus();" onmouseout="this.blur();"></asp:TextBox>


when you hover the textbox you can type in it but when you mouse away you can't (basically speaking)

Mouseover the textbox gains focus with out having to click
Mouseout the textbox loses focus with out having to click away

but this might be a little overkill... just not sure exactly what you want but i think my first post is more like what you are talking about.
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old February 5th, 2009, 01:15 PM
Authorized User
 
Join Date: Dec 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Jason. Thats exactly what I mean.

Where do I insert the TextBox1.focus(); command.

My text box is in a details view and when I add it to code behind page I get an error saying TextBox1 does not exist in the current context.

This is my code behind file:

Code:
public partial class Management_AddNewPin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.focus();
        {
            if (Request.QueryString.Get("Id") != null)
            {
                DetailsView1.DefaultMode = DetailsViewMode.Edit;
            }
        }
    }
    
    protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        EndEditing();
    }
    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["UpdateDateTime"] = DateTime.Now;
    }
    protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        EndEditing();
    }
    protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        e.NewValues["UpdateDateTime"] = DateTime.Now;
    }

    private void EndEditing()
    {
        Response.Redirect("PinEntries.aspx");
    }
    protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
    {

    }
}
You can see where I put it. In the Page_Load.
Is this in the place?

Many thanks for your reply
 
Old February 5th, 2009, 01:20 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default that was just an example...

TextBox1 should be your textbox id and because it's in a detailsview you will have to find it in the detailsview. I'm not totally familiar with them so someone else on here may be better suited to give you a detailed example. i'll try to do some testing on my end and let you know.
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old February 5th, 2009, 06:48 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Andy,

You have at least three ways to do it:

1. Set the DefaultFocus on a Form or Panel control like this in Markup View:

<form id="form1" runat="server" DefaultFocus="txtEmailAddress">

2. Set the default focus in Page_Load by setting the DefaultFocus for the form:

protected void Page_Load(object sender, EventArgs e)
{
Form.DefaultFocus = txtEmailAddress.UniqueID;
}

3. Call the Focus method on a specific control:

protected void Page_Load(object sender, EventArgs e)
{
txtEmailAddress.Focus();
}

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Put cursor at the end of input text peace2007 Javascript 1 October 11th, 2007 04:49 AM
Set cursor at specific location in text box pritz VB How-To 3 August 29th, 2005 10:27 AM
Set cursor at specific location in text box pritz Beginning VB 6 1 August 15th, 2005 12:22 PM
Text box and cursor in it (netscape) maz JSP Basics 0 September 9th, 2004 12:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.