473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with focusing TextBox when Page loads

NawazAhmed
36 New Member
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.c ontrols.textbox
I have also imported system.text

Can someone help me with this.

Thanks and Regards.
Mar 5 '08 #1
3 1619
Plater
7,872 Recognized Expert Expert
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
NawazAhmed
36 New Member
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 Recognized Expert Expert
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
2290
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 response.redirects to the same page. Because I hate the overhead by doing this I'm searching for a cleaner option. But I'm having troubles (off course or I...
4
5026
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 GridView that needs to be dynamically designed, depending on what collection of fields our uses want to edit for their product data. We have 400+...
2
2192
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 fires. So if the user first types the URL of the page in the browser, the "Page_Load" event fires. Then he hits submit, and the form contents are...
6
3139
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 changed by user as well. now, when you press the button the date should be inserted into a database. the problem is that , yes it has been inserted, but...
9
2711
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not...
9
2183
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 "option 3", "option 3" is selected and "option 2" is deselected. So i get '3' in label3 but also still '2' in label2. Same with "option 1". And when i...
0
1595
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" runat="server"></asp:TextBox>
1
2269
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. How can I set focus to a textbox when the tab page is selected? Thank you! Vanessa
2
6931
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 and i am implementing it in my website....
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.