Tabbing not working for Numeric Textbox inside RadGrid

4 posts, 1 answers
  1. Himanshu
    Himanshu avatar
    22 posts
    Member since:
    Jun 2013

    Posted 11 Mar 2014 Link to this post

    I have a rad grid inside there are two numeric textbox and if i change the value of numeric text box it will update the other one as per entered valued. I have applied the tabbing on ItemDatabound command like below:


                    Dim currentPageeindex As Integer = rgPremiumAllocationPlan.CurrentPageIndex * (e.Item.ItemIndex + 1)
                    TryCast(item.FindControl("rtbAllocPercentPAP"), RadNumericTextBox).TabIndex = CShort(currentPageeindex)
                    TryCast(item.FindControl("rtbAllocPremiumPAP"), RadNumericTextBox).TabIndex = CShort(currentPageeindex)
                    TryCast(item.FindControl("lnkRemove"), LinkButton).TabIndex = CShort(currentPageeindex)


    I have applied a blur event on a numeric textbox like below:
     Dim scriptUpdateAmountDue = "updatePremiumAllocationAmountDue(" + Convert.ToString(currentRowIndex) + "," + txtPercentId + "," + txtPremiumId + "," + lnkButtonId + ")"
                    rtbAllocPercentPremium.Attributes.Add("onblur ", scriptUpdateAmountDue)

    On blur event below javascript funtion updatePremiumAllocationAmountDue is called:
    function updatePremiumAllocationAmountDue(currentRowIndex, txtPercentId, txtPremiumAmountId, lnkButtonId) {
        window.ignoreMessage = false;

        if (calledDueToPremiumAllocation == true) {
            calledDueToPremiumAllocation = false;
            return false;
        }

        var rtbAllocPercentPAP = $("input[id$='" + txtPercentId.id + "']");
        var premiumPercent = rtbAllocPercentPAP.val().replace(/,/g, '');

        if (premiumPercent == '') {
            premiumPercent = 0;
            rtbAllocPercentPAP.val(0);
        }
        calledDueToPremiumAllocation = true;
        if (parseFloat(premiumPercent) > 100) {
            alert('Alloc. % value cannot be greater than 100%.');
            rtbAllocPercentPAP.focus();
            calledDueToPremiumAllocation = true;
            return false;
        }
        else {
            $("input[id$='hdnPAPValidate']").val("0");
            if (parseFloat(rtbAllocPercentPAP[0].defaultValue) != parseFloat(premiumPercent)) {
                calledDueToPremiumAllocation = false;


                if (parseFloat(premiumPercent) == parseFloat($("input[id$='hdnAllocPercentValue']").val())) {
                    calledDueToPremiumAllocation = false;
                    return false;
                }


                $("input[id$='hdnPapRowIndex']").val(currentRowIndex.toString());
                //$("input[id$='hdnAllocPercentValue']").val(rtbAllocPercentPAP.val());

                if ($("input[id$='hdnAllocPercentValue']").val() != "$" && parseFloat(premiumPercent) <= 100) {
                    calledDueToPremiumAllocation = false;
                    //        var pos2 = 0;
                    //        pos2 = premiumPercent.indexOf('.');
                    //        if (pos2 > 0) {
                    //            pos2 = pos2 + 5;
                    //            premiumPercent = premiumPercent.substring(0, pos2);
                    //        }

                    $("input[id$='hdnAllocPercentValue']").val(premiumPercent);
                    $("input[id$='btnAllocPercentPAP']").click();

    //                $("input[id$='" + txtPremiumAmountId.id + "']").focus();
    //                $("input[id$='rtbAllocPremiumPAP']").focus();
                }


                calledDueToPremiumAllocation = false;
            }
            else {

                validatePremiumAllocationGridAllPercentItems();
            }
        }
    }



    From above Javascript funtion a button event click event is called: $("input[id$='btnAllocPercentPAP']").click();

    Protected Sub BtnAllocPercentPap_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAllocPercentPAP.Click

            Dim allocPercentValue As Decimal
            Dim allocPremiumValue As Decimal
            ulErrorMessagePAP.InnerHtml = String.Empty

            Try

                If TypeOf sender Is Button Then

                    Dim rowIndex As Integer = Convert.ToInt32(hdnPapRowIndex.Value)
                    Try

                        '      hdnPremiumFooterTotalAmountDue.Value = InvoiceDetailsData.Premiums.Compute _
                        '("Sum(" + InvoiceDetailsData.Premiums.AmountDueUIColumn. _
                        ' ColumnName + ")", PolicyInfoConstants.premiumAllocationFilterRowNotDeleted)
                        If (InvoiceDetailsData IsNot Nothing AndAlso InvoiceDetailsData.Premiums IsNot Nothing AndAlso InvoiceDetailsData.Premiums.Rows.Count > 0) Then

                            hdnPremiumFooterTotalAmountDue.Value = (From drow As DataRow In InvoiceDetailsData.Premiums Where _
                                                        drow.RowState <> DataRowState.Deleted AndAlso _
                                                        drow(InvoiceDetailsData.Premiums.RowStateColumn.ColumnName) <> "Deleted" AndAlso Not _
                                                        IsDBNull(drow(InvoiceDetailsData.Premiums.AmountDueUIColumn.ColumnName))). _
                                                        Sum(Function(drow) CType(drow(InvoiceDetailsData.Premiums.AmountDueUIColumn.ColumnName).ToString(), Decimal))

                        Else

                            hdnPremiumFooterTotalAmountDue.Value = "0"

                        End If

                    Catch ex As Exception
                        hdnPremiumFooterTotalAmountDue.Value = "0"
                    End Try


                    Dim rgpremiumAllocationPapItem As GridDataItem = rgPremiumAllocationPlan.MasterTableView.Items.Item(rowIndex)
                    'NE-3368
                    Dim premiumAllocationKeyDataColumn As RadNumericTextBox = DirectCast(rgpremiumAllocationPapItem.FindControl("hdnPremiumAllocationkeyDataColumn"),  _
                        RadNumericTextBox)
                    'NE-3412
                    Dim invoiceDetailDatasetRow As DataRow = _
                        InvoiceDetailsData.PremiumAllocation.Rows.Find(DirectCast(rgpremiumAllocationPapItem.FindControl("hdnPremiumAllocationkeyDataColumn"), RadNumericTextBox).Text)

                    Dim keyValue As Integer = -1
                    If (invoiceDetailDatasetRow IsNot Nothing) Then
                        keyValue = (From row In InvoiceDetailsData.PremiumAllocation.AsEnumerable() _
                                    Let r = row.Field(Of Integer)(InvoiceDetailsData.PremiumAllocation.PremiumAllocationkeyDataColumn.ColumnName) _
                                   Where r = invoiceDetailDatasetRow(InvoiceDetailsData.PremiumAllocation.PremiumAllocationkeyDataColumn.ColumnName) _
                                   Select InvoiceDetailsData.PremiumAllocation.Rows.IndexOf(row)).FirstOrDefault()
                        'invoiceDetailDatasetRow(InvoiceDetailsData.PremiumAllocation.PremiumAllocationkeyDataColumn.ColumnName)
                    End If
                    'NE-3412
                    'NE-3368
                    Dim rtbAllocPercentPap As RadNumericTextBox = DirectCast(rgpremiumAllocationPapItem.FindControl("rtbAllocPercentPAP"),  _
                      RadNumericTextBox)
                    Dim rtbAllocPremiumPap As RadNumericTextBox = DirectCast(rgpremiumAllocationPapItem.FindControl("rtbAllocPremiumPap"),  _
                       RadNumericTextBox)
                    'Dim rtbAllocPercentPap As RadNumericTextBox = DirectCast(sender,  _
                    '    RadNumericTextBox)
                    'Dim rgpremiumAllocationPapItem As GridItem = _
                    '    DirectCast(rtbAllocPercentPap.NamingContainer, GridItem)
                    'Dim rtbAllocPremiumPap As RadNumericTextBox = DirectCast( _
                    '    rgpremiumAllocationPapItem.FindControl("rtbAllocPremiumPAP"),  _
                    '    RadNumericTextBox)
                    'NE-3412
                    'InvoiceDetailsData.PremiumAllocation.DefaultView.RowFilter = PolicyInfoConstants.premiumAllocationFilterRowNotDeleted
                    InvoiceDetailsData.PremiumAllocation.DefaultView.RowFilter = String.Empty
                    'NE-3412

                    If Not String.IsNullOrEmpty(Server.HtmlEncode(hdnAllocPercentValue.Value)) Then

                        allocPercentValue = _
                            Convert.ToDecimal(Server.HtmlEncode(hdnAllocPercentValue.Value))
                        allocPercentValue = ParsingHelper.RoundDecimal(allocPercentValue, 4)

                        If (allocPercentValue > 100) Then
                            rtbAllocPercentPap.Text = 100
                            allocPercentValue = 100

                        End If

                        If Not String.IsNullOrEmpty(hdnPremiumFooterTotalAmountDue.Value) Then

                            allocPremiumValue = (((Convert.ToDecimal(hdnPremiumFooterTotalAmountDue.Value)) * allocPercentValue) / 100)
                            allocPremiumValue = ParsingHelper.RoundDecimal(allocPremiumValue, 2)

                            InvoiceDetailsData.PremiumAllocation. _
                            DefaultView(keyValue).Row("AllocPremiumAmount") = _
                                       Convert.ToString(allocPremiumValue)

                            InvoiceDetailsData.PremiumAllocation.DefaultView _
                                (keyValue). _
                                Row("AllocationPercentage") = allocPercentValue

                            InvoiceDetailsData.PremiumAllocation.DefaultView( _
                                keyValue). _
                            Row("PolicyID") = PolicyID

                            allocPremiumValue = ((Convert.ToDecimal(hdnPremiumFooterTotalAmountDue.Value)) * _
                                  allocPercentValue) / 100
                            allocPremiumValue = ParsingHelper.RoundDecimal(allocPremiumValue, 2)
                            rtbAllocPremiumPap.Text = Convert.ToString _
                                (allocPremiumValue)


                            If IsPlanSelected() Then
                                lnkAddNewAllocationPlan.Enabled = False
                                _isPremiumPlanAllocationGridInEditMode = True
                            End If


                        End If
                    Else

                        InvoiceDetailsData.PremiumAllocation.DefaultView(keyValue)("AllocPremiumAmount") = 0
                        InvoiceDetailsData.PremiumAllocation.DefaultView _
                                (keyValue). _
                                Row("AllocationPercentage") = 0


                    End If

                    If (InvoiceDetailsData.PremiumAllocation.DefaultView(keyValue) _
                               (InvoiceDetailsData.PremiumAllocation.RowStateColumn.ColumnName) = _
                               PolicyInfoConstants.addedRow) Then
                        InvoiceDetailsData.PremiumAllocation.DefaultView _
                            (keyValue) _
                            (InvoiceDetailsData. _
                             PremiumAllocation.RowStateColumn. _
                             ColumnName) = PolicyInfoConstants.addedRow

                    Else

                        InvoiceDetailsData.PremiumAllocation.DefaultView( _
                            keyValue) _
                            (InvoiceDetailsData. _
                             PremiumAllocation.RowStateColumn. _
                             ColumnName) = PolicyInfoConstants.modifiedRow
                    End If
                    'NE-3412
                    InvoiceDetailsData.PremiumAllocation.DefaultView.RowFilter = PolicyInfoConstants.premiumAllocationFilterRowNotDeleted
                    'NE-3412
                    PolicyInfoBO.AddUpdateCacheSerializeObject(_policyInfoDataKey, _
                                                           InvoiceDetailsData, True)

                    BindPremiumAllocationPlan()
                    rgPremiumAllocationPlan.Rebind()
                    hdnAllocPercentValue.Value = "$"

                End If

            Catch ex As Exception

            End Try

        End Sub




    Now the problem is that when i enter a amount a amout in a textbox and do tab out it focus on next numeric textbox but then auto btn event is called and after completion of this event it get lost. Please refer screent shot 1. In this if i enter value of a row of Alloc. % and do the tab, when the loader apprear on the screen it sets the focus on the corresponding Alloc.Prem but when the postback operation gets completed and loader gets removed the focus gets lost automatically.

    Any suggesstion will be helpful.
  2. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 14 Mar 2014 Link to this post

    Hello Himanshu,

    I have examined your scenario and I may confirm that it is expected to lose the focus after a postback.

    What I could suggest for your requirement is that you handle the OnRequestStart and OnResponseEnd client-side events of your RadAjaxManager/RadAjaxPanel to first save the current focused control and then to focus it again after the request.

    The following simple example should cover all scenarios correctly:
    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            var elementToFocusID = null;
     
            function onRequestStart(sender, args) {
                elementToFocusID = document.activeElement.id;
            }
     
            function onResponseEnd(sender, args) {
                if (elementToFocusID) {
                    if (document.getElementById(elementToFocusID)) {
                        document.getElementById(elementToFocusID).focus();
                    }
                }
                 
                elementToFocus = null;
            }
        </script>
    </telerik:RadCodeBlock>
     
    <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" ClientEvents-OnRequestStart="onRequestStart" ClientEvents-OnResponseEnd="onResponseEnd">
        <%--your content--%>
    </telerik:RadAjaxPanel>

    Hope that helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Himanshu
    Himanshu avatar
    22 posts
    Member since:
    Jun 2013

    Posted 04 Apr 2014 in reply to Konstantin Dikov Link to this post

    Thanks Konstantin Dikov.......
  5. Phil
    Phil avatar
    15 posts
    Member since:
    Mar 2012

    Posted 12 Apr Link to this post

    Big thanks! This fixed a postback refocus issue i was having, even solved the same issue when clicking from control to another control.

    Been searching for about half a day and finally found this!

     

     

Back to Top