locked
radio button focus works in chrome but not in IE RRS feed

  • Question

  • User-944424728 posted

    Hello, I have 3 radio buttons which is yes, no, and I do not wish to answer.  Using the code below, it works in Chrome when you check yes, the focus stay on yes, when you check no, focus stay where it at with all the autopost back but it does not work in IE. Please advise.  I tried to add {2} and the focus stay where it's at in IE but no autopost back on "no" check and it's also give me compile error at {2} which it said format string contains invalid placeholder . Thank you.

    --

    Private Sub rblDisabilityTx_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblDisabilityTx.SelectedIndexChanged
    pnlTxDisabilityItems.Visible = (rblDisabilityTx.SelectedValue = "1")
    If Not pnlTxDisabilityItems.Visible Then
    cblCategoryOfDisability.ClearSelection()
    For Each item As ListItem In cblCategoryOfDisability.Items
    item.Enabled = True
    Next
    rblConcernDisability.ClearSelection()

    End If

    ScriptManager.RegisterStartupScript(aupTxDisability, aupTxDisability.GetType, "rblDisabilityTxTriggerFocus",
    String.Format("$('#{0}_{1}').focus();", rblDisabilityTx.ClientID, rblDisabilityTx.SelectedIndex),
    True)

    End Sub
    --
    <asp:UpdatePanel ID="aupTxDisability" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <GSI:GSIContainer ID="cntHasDisabilityTx" runat="server" ForControl="rblDisabilityTx" Label="<% $ Resources: DisabilitySubstantial%>"
    IncludeLabelColon="False" Width="100%" LabelWidth="263px">
    <asp:RadioButtonList ID="rblDisabilityTx" runat="server" AutoPostBack="true" Style="float: left;" role="radiogroup" aria-label="<% $ Resources: DisabilitySubstantial%>">
    <asp:ListItem Value="1" Text="<%$ Resources: DisabilitySubstantialYes %>" />
    <asp:ListItem Value="0" Text="<%$ Resources: DisabilitySubstantialNo %>" />
    <asp:ListItem Value="9" Text="<%$ Resources: DoNotWishToAnswer %>" />
    </asp:RadioButtonList>
    </GSI:GSIContainer>

    --tried code below but not work

    'rblDisabilityTx.Focus()
    'ScriptManager.RegisterStartupScript(Me, Me.GetType, "rblDisabilityTxTriggerFocus",
    ' String.Format("$('#{0}_{1}_{2}').focus();", rblDisabilityTx.ClientID, rblDisabilityTx.SelectedIndex),
    ' True)

    Thursday, June 6, 2019 8:19 PM

All replies

  • User-1174608757 posted

    Hi apvbnet,

    According to your description,could you please tell me the version of your IE browser?Since your code works well in Chrome but not work in IE, I suggest that you could update your IE browser to IE11. IE11 support most of plugins used in front end.

    Here is the link.I hope it could help you.

    https://www.laptopmag.com/articles/how-to-update-internet-explorer

    Best Regards

    Wei

    Friday, June 7, 2019 7:04 AM
  • User-944424728 posted
    It’s IE11
    Friday, June 7, 2019 10:32 AM
  • User-1174608757 posted

    Hi aspvbnet,

    So I think it is the  problem  about browser setting.I think you may have checkbox show intranet sites in compatibility view checked in your IE setting . I suggest that you could uncheck it  and see the result.

    Best Regards

    Wei

    Monday, June 10, 2019 1:29 AM
  • User-1038772411 posted

    Hi, aspvbnet

    A solution may be adding a keypress event to the previous field and use the click event on the radios. Also, move the control.focus(); out of the if statement:

    Javascript

    function changeFocus(next) {
        gotFocus(next);
    }
    
    function gotFocus(control) { 
        document.getElementById('form1').tabSelected.value = control.id; 
        control.focus();
    
        if (control.type == "text") { 
            if (control.createTextRange) { 
                //IE   
                var FieldRange = control.createTextRange(); 
                FieldRange.moveStart('character', control.value.length); 
                FieldRange.collapse(); 
                FieldRange.select(); 
            } 
            else { 
                //Firefox and Opera   
                var length = control.value.length; 
                control.setSelectionRange(length, length); 
            } 
        } 
    } 

    Thanks.

    Wednesday, June 12, 2019 5:58 AM