How to put cursor in textbox onload

A

Asad

I really really really need to put the cursor in a text box at onload.
I can't figure out how to do this in ASP.NET. Anyone? In ASP.NET,
javascript, anything ...
 
A

Ashish M Bhonkiya

Hi asadikhan,

you can use the following sample script to do this, Replace the TextBox1
with the name of the control to which you want to set the focus to

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
StringBuilder myJavaScript = new StringBuilder();

myJavaScript.Append("<script language='Javascript'> function
setfocus(){");
myJavaScript.Append("document.getElementById(\"" +
TextBox1.ClientID + "\").focus();");
myJavaScript.Append("} setfocus();</script>");

this.RegisterStartupScript("SetFocusScript",
myJavaScript.ToString());
}

HTH
Regards
Ashish M Bhonkiya
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top