setting focus to a textbox

T

test test

Hi,

How can I set focus to a particular textbox on an aspx page in vb code? My
problem is caused by the page updating when a user clicks a command button
and I execute code (like updating a price when you click "Calculate" button,
etc.). The button they click and the "Total" field is down toward the
bottom of the web page and when the page updates, it resets to the top like
you just opened the page.

I have searched on the "Focus" method and my compile says:
'focus' is not a member of 'System.Web.UI.Webcontrols.TextBox'.

My code just reads: Textbox1.focus()

Help.
 
K

Kevin Spencer

This has to be done on the client side using JavaScript. Example:

document.forms[0].Textbox1.focus();

NOTE: This uses the Name property of the text box. To use the ID, you would
use:

document.getElementById("Textbox1").focus();

If you need to set the focus while handling a PostBack, just use
Page.RegisterStartupScript() to insert the script in the page so that it
executes on the client when the page loads.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top