Hello,
I have a login page that requires only a password from the user. The password field is a text box and I'm trying to get the cursor to automatically be in the text box when they first load the page. We're using C# for the page, but from what I hear it might require Javascript? I'm very new to working with asp pages so I wouldn't even know where on the page I would put the code. I've tried "txtpassword.Focus();" but when I click on the link to our page the cursor is still not there. I've also read a lot about using javascript so I've tried the following code with no luck (I changed TextBox1 to the name of my textbox but that didn't work):
I've also seen a lot of code with "form1" and they say to just change it to what my form is, but I've looked and cannot find "form" anywhere in my code.
Please help!
Thanks in advance.
I have a login page that requires only a password from the user. The password field is a text box and I'm trying to get the cursor to automatically be in the text box when they first load the page. We're using C# for the page, but from what I hear it might require Javascript? I'm very new to working with asp pages so I wouldn't even know where on the page I would put the code. I've tried "txtpassword.Focus();" but when I click on the link to our page the cursor is still not there. I've also read a lot about using javascript so I've tried the following code with no luck (I changed TextBox1 to the name of my textbox but that didn't work):
Code:
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());
}
I've also seen a lot of code with "form1" and they say to just change it to what my form is, but I've looked and cannot find "form" anywhere in my code.
Please help!
Thanks in advance.