Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 December 7th, 2005, 10:51 AM
Authorized User
 
Join Date: Nov 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default aspx cursor position

Simple question.

I have set up TabIndex order for all my fields on an aspx form that
displays in internet explorer.

When my aspx application comes up in internet explorer I would like to position the cursor on the first input field. But on startup the cursor does not start on the first input field.

So as to be clear the tab works wonderfully going left to right field to field, it is only on start up that the cursor does not start on the form.



 
Old December 8th, 2005, 11:38 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to emit javascript that sets the focus the desired field:

document.getElementById('txtTextBoxControl').focus ();

-Peter
 
Old December 9th, 2005, 09:40 AM
Authorized User
 
Join Date: Nov 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much,

I went in and added a java script in the apsx page. It worked.
<script language="javascript" type="text/javascript">
        function setCursor() {
            document.getElementById('txtName').focus();
        }
</script>
Set <body... onload="setCursor()"...

This did not work, but I am not to overly concerned about it, added
this to page load event in aspx.vb
Response.Write("<script language='javascript'> { document.getElementById('txtName').focus(); }</script>")




 
Old December 27th, 2005, 10:43 AM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sure to be criticized, but here it goes.

Well all was well, my application opened with the cursor position
in the first entry field. I was happy.

I did it as follows:
<body bgColor="#dce0e1" onload="setCursor()" MS_POSITIONING="GridLayout">

With the function as a java script (which I simply added by opening
up my application in html display mode):

<script language="javascript" type="text/javascript">
    function setCursor() {
        document.getElementById('txtName').focus();
    }

I have been asked to place the cursor position
on other fields when they are selected. This would seem quite simple
except that I coded my aspx application using all aspx controls.

So I do not have an html but all <asp: > ... </asp...>

My problem is I cannot call my java function from an on load event,
except in the case of the html body load. The java script was
simply added by going into html display mode.

I have tried writing the java script with response.write on a
control event and it writes it to the html display page, but does
not fire.

Well I am sure to have been to confusing, I apologize. Let the ax fall.





 
Old December 28th, 2005, 03:40 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What do you mean by "I have been asked to place the cursor position on other fields when they are selected."?

If you select a field, doesn't it get focus automatically?

-Peter
 
Old December 28th, 2005, 04:21 PM
Authorized User
 
Join Date: Nov 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yep, I apologize for not being clear enough.
What I did, and it works/looks good is I have some hidden fields that only appear when a drop down list selection of 'OTHER' is selected. When that happens I would like to place the cursor on one of the new fields that 'appear' to the end user.


 
Old December 29th, 2005, 10:51 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I wrote some helper functions for emitting scripts to the page some time ago that I posted on this thread (in my last post):

http://p2p.wrox.com/topic.asp?TOPIC_ID=17294

Using the ScriptLet method, call it with the focus javascript with the control you want to focus on:

ScriptLet(String.Format("document.getElementById(' {0}').focus();", control.ClientID()))

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting cursor position from grid view yuenli C# 2005 0 August 6th, 2008 03:48 AM
keyboard cursor position rahesh VB.NET 1 May 8th, 2008 01:27 PM
Cursor.Position iremtoksoz C# 3 January 2nd, 2008 11:41 AM
Word-cursor position using mouse is not changing jahid Pro VB 6 2 February 6th, 2007 05:32 AM
How to set cursor position in a textbox? zayasv VB.NET 2 April 29th, 2006 07:09 AM





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