473,396 Members | 1,756 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.

Activate a text box?

How would I have a textbox on my web form that will automatically have a
blinking cursor in it when the page loads?
Closest I've come so far is having to press tab once to put the cursor in
there.

Thanks!

Matt
Nov 18 '05 #1
2 1331
Hello Matt,

already tried some ClientSide "Action" (javascript -
focus...)?

Regards

Tom

-----Original Message-----
How would I have a textbox on my web form that will automatically have ablinking cursor in it when the page loads?
Closest I've come so far is having to press tab once to put the cursor inthere.

Thanks!

Matt
.

Nov 18 '05 #2
this is what i use. just pass in the control you want to set focus to. end
of story

/// <param name="control">Control to set the InitialFocus on.</param>
public static void SetInitialFocus(System.Web.UI.Control control)
{
if (control.Page == null)
{
throw new ArgumentException(
"The Control must be added to a Page before you can set the IntialFocus
to it.");
}
if (control.Page.Request.Browser.JavaScript == true)
{
// Create JavaScript
System.Text.StringBuilder s = new System.Text.StringBuilder();
s.Append("\n<SCRIPT LANGUAGE='JavaScript'>\n");
s.Append("<!--\n");
s.Append("function SetInitialFocus()\n");
s.Append("{\n");
s.Append(" document.");

// Find the Form
System.Web.UI.Control p = control.Parent;
while (!(p is System.Web.UI.HtmlControls.HtmlForm))
p = p.Parent;

s.Append(p.ClientID);
s.Append("['");
s.Append(control.UniqueID);
// Set Focus on the selected item of a RadioButtonList
System.Web.UI.WebControls.TextBox rbl = control as
System.Web.UI.WebControls.TextBox;
s.Append("'].focus();\n");
s.Append(" document.");

// Find the Form
p = control.Parent;
while (!(p is System.Web.UI.HtmlControls.HtmlForm))
p = p.Parent;

s.Append(p.ClientID);
s.Append("['");
s.Append(control.UniqueID);
// Set Focus on the selected item of a RadioButtonList
rbl = control as System.Web.UI.WebControls.TextBox;
s.Append("'].select();\n");
s.Append("}\n");

if (control.Page.SmartNavigation)
s.Append("window.setTimeout(SetInitialFocus, 500);\n");
else
s.Append("window.onload = SetInitialFocus;\n");

s.Append("// -->\n");
s.Append("</SCRIPT>");

// Register Client Script
control.Page.RegisterClientScriptBlock("InitialFoc us", s.ToString());
}
}
--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Tom Egginger" <T.********@ggmmxx.net> wrote in message
news:25*****************************@phx.gbl...
Hello Matt,

already tried some ClientSide "Action" (javascript -
focus...)?

Regards

Tom

-----Original Message-----
How would I have a textbox on my web form that will

automatically have a
blinking cursor in it when the page loads?
Closest I've come so far is having to press tab once to

put the cursor in
there.

Thanks!

Matt
.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: geotso | last post by:
Hi I'm looking for a script to activate a different stylesheet for a page, according the link a visitor clicks on. More specific, I have a page with a topic, divided into three sub-topics. I...
4
by: bughunter | last post by:
In version 7.x connect to db activate db db SQL1494W Activate database is successful, however, there is already a connection to the database. works fine - db activated. In 8.x - No!...
5
by: Adda | last post by:
In a Parent mdi form I have a datagrid. I select a record from the grid and then invoke a childmdi form. I add the childmdi to an arraylist to keep track of it. If a user has selected multiple...
2
by: Dave Booker | last post by:
I have a Windows form application that I generally run minimized. When a critical event occurs it instantiates another "Alert" form which I want to grab the user focus. In the Alert constructor...
0
by: LostInMD | last post by:
Hi, I am loading word with vb2005 customized commandbars. During the load of the Word exe, the exe automatically opens a new document. I am having difficulty "activating" the open document...
5
by: Simon | last post by:
Hi there, How can i activate, for example, the insertkey, without pressing the key itself? Something like: "window.event.keyCode = 45" won't work. Any ideas? It should happen onfocus, and...
4
by: jonny | last post by:
I would like to add a password and user name to my website. If the username and password is correct than activate the hyperlinks and buttons. Could you please share some code how how to achieve...
7
by: Andrus | last post by:
I have UserControls in MDI child forms containing TextBoxes and other controls. When user re-activates form, I need that Control which was last activated is activated again. Currently *first*...
17
by: happyse27 | last post by:
Hi All, The html page(see item a below) is calling javascript(item b below), but cant work as the page show blank. Not sure if the method of calling is wrong(in terms of default directory) or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.