I have an app that was built in an earlier version of ASP.NET 1.1. I have upgraded most of the app to 4.0 (HTML5) and I am trying to set focus to a textbox when a form loads but ever since I have upgraded to IE 11 this is not working. The previous developer has a script on the server side to set the focus to the txtName textbox and injects it before the page renders. FYI, I added a ScriptManager because I added an AJAX control so if that comes into play please let me know
Here is the call to the function in the markup in the body tag.
The underlined piece of code above is what Im trying to get to work. I have tried numerous different types of code snippets but nothing has worked. I actually got it to work momentarily using the .ready function in jquery but have since lost the code and cant get it to work again. I have also tried to add a newer version of a jquery file(jquery-1.12.1.min.js) to see if that would help but it hasnt. I have tried multiple functions like these
1. in place of the underlined code above
' // Reference the textbox
var txt = document.getElementById("<%=txtName.ClientID%>"); 'also tried txtName without ClientID
' // If the textbox was found, call its focus function
if (txt != null)
2. Also Tried all of these in the markup in the <Head> tag
I am curious if maybe I could do this in the CSS instead? Anything that will get this to work I am willing to try. Just a thought...
Open in new window
There's no need to test for null. If the element doesn't exist on the page, the code will be ignored.