Focus on text box

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.
	<body bgColor="#ffffff" background="./images/testbg.gif" style="margin-top:0" MS_POSITIONING="GridLayout" [b]onload="sf()"[/b]>

Open in new window

Then in the code behind this is what is running but like I said, in IE 11 this does not work(all other versions and browsers seem to be working fine).
'insert missing tags in the default markup
    Private Function FixMarkup(ByVal gridMarkup As String) As String
        'local variables
        Dim StrScript As String
       [b] If rbtnNameSearch.Checked = True Then
            StrScript = "function sf()" _
            & " { " _
            & " document.Form1.txtName.focus(); " _
            & " }"
            StrScript = "function sf()" _
            & " { " _
[u]            & " document.Form1.txtFileNumber.focus(); " _[/u]
            & " } " _
            & "function validateRange(source,Args){" _
            & "if (Args.Value > 999 && Args.Value < 999999)" _
            & "  Args.IsValid = true;" _
            & "else" _
            & "  Args.IsValid = false;" _
            & " return;" _
            & "}"[/b]
        End If
        'find the 1st occurrence of <head> and insert <link href="MainCss.css" type="text/css" rel="stylesheet">
        Dim insertpoint As Integer
        insertpoint = gridMarkup.IndexOf("language=""javascript"">") + ("language=""javascript"">").Length
        gridMarkup = gridMarkup.Insert(insertpoint, StrScript)

        Return gridMarkup
    End Function

Open in new window

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
<script src="Scripts/jquery-1.12.1.min.js"></script>    
        <script type="text/javascript">
            $(function () {
                $("#txtName").focus(function () {
                    alert("hello world");

         <script type="text/javascript" >
             $(document).ready(function () {

        <script type="text/javascript" language="javascript">
            function TestFocus() {
                // Reference the textbox
                var txt = document.getElementById("<%=txtName.ClientID%>");

                // If the textbox was found, call its focus function
                if (txt != null)
                    alert("Nothing here");

Open in new window

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...

I must tell you that I am not a javascript/jqeury guy(but I am learning) so its kinda foreign to me so if I am missing something simple dont be surprised. I have been on this for a few days now and need to move on so please help me out. It would be greatly appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
If this is a control, you'll need to use $('#<%=txtName.ClientID%>') to target the element.  Try this:

$(document).ready(function() {

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.
jknj72Author Commented:
I have tried this and still not working. I believe it is something else going on with this. I can see that the mouseover on the textbox changes the border color but I still cannot click in the text box and enter data. I obviously dont know what it is but I think it could be something else that I may have installed or something else that Im doing/running that is causing this not to work correctly.
I am using HTML5 and I am referencing <script src=""></script>
Like I said, Im kinda new to javascript and jquery so I am pretty much lost here so ANY help is greatly appreciated..

zephyr_hex (Megan)DeveloperCommented:
can you post the HTML that's rendered by the control?
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

jknj72Author Commented:
I cant get to the page where the focus should be happening now. Somehow I have lost the ability to get to the page ever since I upgraded to IE 11. Its not a javascript error either, I have run the same code on my co-workers machines and it works fine. Ever since I upgraded browsers I have been stuck. I want to check all versions and make sure everything is the same as other developers where it works. If you have any thoughts on where I could check to make sure I am running the correct stuff please let me know. I can show you what I have and maybe we can figure it out...
Thanks for all your help!
zephyr_hex (Megan)DeveloperCommented:
If you just need to test versions of IE, you can use something like this:

You should check your browser's dev tool (F12) console  -- in many cases, it will show errors if the page is failing to work correctly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jknj72Author Commented:
Well now I cannot get to the page that I was originally having the problem with. I am getting redirected to a custom Errors page and I cannot find the issue when I am redirected there. I am trying to figure that out now and get back to my original issue. I will check out your link and get back to you...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.