setting focus to a textbox

  • Thread starter Thread starter test test
  • Start date Start date
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.
 
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.
 
Back
Top