Default focus in a form or panel does not set inside a Web browser control


I am using defaultfocus property to set default focus in a form or panel. I am trying to set default focus for textbox and it works properly in a browser.

But when the same page is loaded using web-browser control in VB6 i am facing the problem. The default focus will not set when page loaded using web-browser control(VB6 Microsoft internet controls). I tried using the same for a simple form and it does not work. I tried using .focus in page load and it also not working inside web-browser control. Then I tried refreshing the page as shown below

WebBrowser1.Navigate "url here"
WebBrowser1.Refresh

If i use refresh then focus will be set properly. But this will load the page again(it loads form of aspx again). So is there any other better solution which I can do within my ASP website? or any solution which can do the same?

I tried various methods of doing this through the WinForm code and it was not very effective. If you're needing to set the focus to a textbox, you'll probably have better luck using JavaScript.

If the textbox is a ASP.net server control, you can use:

<html>
<head>
</head>
<body>

<form runat="server">


    <asp:TextBox id="FirstBox" runat="server" /><br>
    <asp:TextBox id="SecondBox" runat="server" />

    <script language="javascript" type="text/javascript">
        var field = '<%= SecondBox.ClientID%>';
        document.getElementById(field).value = field;
        document.getElementById(field).focus();
        document.getElementById(field).select();
    </script>
</form>

</body>
</html>

enter image description here


This is a placeholder post.

    '--- fix WebControl compatibility
    lIEMajor = C_Lng(At(Split(pvGetFileVersion(CreateInstance(PROGID_FSO), GetSpecialFolder(ucsOdtSystem) & "\ieframe.dll"), "."), 0))
    If lIEMajor > 7 Then
        With InitRegistryAccess(ucsRegNone, "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION")
            If .ReadProperty(GetErrorProcessName(), 0, ucsRvtDword) < lIEMajor * 1000 Then
                .WriteProperty GetErrorProcessName(), lIEMajor * 1000, 0, ucsRvtDword
            End If
        End With
    End If

Code above uses lots of helper functions/classes but the idea is clear -- get IE major, if IE7 or above -> multiply major by 1000 and update HKCY_CURRENT_USER's key if needed

Will update extract snippet and include API declares later.