473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with focusing TextBox when Page loads

NawazAhmed
Hi,
I am working with Visual Studio 2003, framework 1.1
I am trying to focus a textbox when page loads. I tried
Expand|Select|Wrap|Line Numbers
  1. Page.RegisterStartupScript("focus", "<script>document.getElementById('name').focus();</script>")
  2. and 
  3. textbox.focus()
  4. and 
  5. textbox.setfocus()
  6.  
  7.  
but it says focus or setfocus is not there in system.web.ui.controls.textbox
I have also imported system.text

Can someone help me with this.

Thanks and Regards.
Mar 5 '08 #1
3 1612
Plater
7,872 Expert 4TB
You seem to be mixing your behaviours considerably.
What you want is a javascript function to run in the "onload" event of the page.
In that function you would set the focus of the control.

Something like:
Expand|Select|Wrap|Line Numbers
  1. function myfocus() 
  2. {
  3.    var mytext = document.getElementById("mytext2");
  4.    mytext.focus();
  5.    mytext.select();
  6. }
  7.  
Then assign it to the onload attribute of your page.
Mar 5 '08 #2
Hi, Thanks for the reply.
As u mentioned, the javascript code should be in the code behind or seperate javascript file?
What abt onload event is it the one which is in the code behind???If yes then how will u write the javascript code in code behind?
And I am using asp button not the html one.
How you will be implementing this could u give me a complete example.

Thanks.
You seem to be mixing your behaviours considerably.
What you want is a javascript function to run in the "onload" event of the page.
In that function you would set the focus of the control.

Something like:
Expand|Select|Wrap|Line Numbers
  1. function myfocus() 
  2. {
  3.    var mytext = document.getElementById("mytext2");
  4.    mytext.focus();
  5.    mytext.select();
  6. }
  7.  
Then assign it to the onload attribute of your page.
Mar 5 '08 #3
Plater
7,872 Expert 4TB
You said on page load, nothing about a button press, so I am giving you the examples for how to do it on page load.
Stick the javascript in your aspx file. Then add the onload attribute to your body element.
Expand|Select|Wrap|Line Numbers
  1. <body onload="myfocus();" >
  2.  
For a button press you would do different things.
Mar 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
4
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a...
2
by: COHENMARVIN | last post by:
I have a form with a Submit button. The user fills out the form, clicks the submit button, and then the page posts back to itself. Every time the page posts back to itself, the "Page_Load" event...
6
by: Chris | last post by:
I created a very simple web page in asp.net. there are only a textbox and a button on the page. when the page loads into web browser there is current date in the textbox. but the date can be...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
9
by: Bob Malcoprs | last post by:
Hi, I want to get all the selected values of a listbox in several labels.. With this code here below, when i click on e.g. "option 2", i get '2' in label2. That's ok. But if i then click on...
0
by: silpa | last post by:
Hi, I have a problem with calendar extender. Example: <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:TextBox ID="TextBox1"...
1
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi all! I have a tab control and when I access a tab page I'd like to focus on a textbox. I am using someTextBox.Focus() on tabPage_Enter() event, but it is not focusing in the someTextBox. ...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.