ASP.Net下拉列表 - 多个回发

时间:2016-03-07 13:34:44

标签: asp.net vb.net postback autopostback

我在下拉列表中有一些不一致的行为。

当它回发并且所选索引为1时,它会通过并按预期工作,获取数据,构建UI,并将所有内容写入屏幕。

如果所选索引为2,那么它将通过BuildUI()方法,然后再次通过循环,认为所选索引为0,然后不构建UI。

这是代码

Protected Sub Page_Complete() Handles Me.LoadComplete

    If _IsAuth = True Then
        'if user is authorised to use the application, and the drop down menu has UK or GE 
        'selected then the the UI will be build for the user. 
        If Page.IsPostBack And ddlCharterVersion.SelectedIndex > 0 Then

            BuildUI()
            'once the UI has been built the dropdown list is to be hidden
            ScriptManager.RegisterStartupScript(Me, GetType(Page), "ddlCharterVersion", "$('#paymentType').hide();", True)
        Else
            'if the user is not authorised they are passed a message showing that they are not authorised from the master
            'page and the panel holding the divs and information will be hidden
            ScriptManager.RegisterStartupScript(Me, GetType(Page), "hidePayments", "$('#panelHead').hide();", True)
        End If
    End If

End Sub

Protected Sub ddlCharterVersion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlCharterVersion.SelectedIndexChanged
    ddlCharterVersion.Enabled = False
End Sub

这是页面上的下拉菜单。

<div class="col-md-10 pull-left "><asp:dropdownlist runat="server" width="200px" id="ddlCharterVersion" AutoPostBack="True">
        <asp:ListItem Value="-- Select Charter Version -- ">-- Select Charter Version -- </asp:ListItem>
        <asp:ListItem Value="UK">UK</asp:ListItem>
        <asp:ListItem Value="GE">GE</asp:ListItem>
 </asp:dropdownlist></div>

调试应用程序时,我没有遇到任何应该导致页面回发的错误。

最令我困惑的是,所选择的指数位置1工作正常,位置2没有。

如果有人能直接看到问题所在,我将非常感谢你的帮助。

- 更新 -

enter image description here

- 更新2 -

调试时,我从来没有遇到任何异常,并且每个异常都有一个断点,并且没有一个被击中。

 Protected Sub BuildUI()
    'gets the next record for payment
    GetNextRecordForPayment()
    If noRecords = False Then
        'if there are records, concatenate the list of payments into one row in a list
        ConcatenateListOfPayments()
        ''write the records to the UI
        writeRecordsToUI()
    End If

End Sub

Protected Sub GetNextRecordForPayment()
    Try

        ''if a user already has a record locked and has refreshed the page for any reason 
        ''get this record back until they pass it to the excptions queue or validate for payment

        'UserHasRecordLocked is returned as an object. Either as the contactId of the locked record or False
        Dim UserHasRecordLocked = CheckForLockedRecord()
        Dim lockedRecord As Long
        Dim contactIdParam As New SqlParameter("@LockedRecord", SqlDbType.BigInt)
        Dim charterVersionParam As New SqlParameter("@CharterVersion", SqlDbType.VarChar)
        charterVersionParam.Value = ddlCharterVersion.SelectedValue

        'check the type of object of UserHasRecordLocked
        If UserHasRecordLocked.GetType = GetType(Long) Then
            'if it has a record then assign the value of UserHasRecordLocked
            'to the sqll parameter.
            contactIdParam.Value = UserHasRecordLocked
        Else
            'else give it a default value
            contactIdParam.Value = 99999
        End If

        'place all parameters into a list object of sql parameter
        'this has been done this way so that you dont have to be 
        'precious or careful of where you place your parametss
        Dim listOfParam As New List(Of SqlParameter)

        listOfParam.Add(contactIdParam)
        listOfParam.Add(charterVersionParam)
        ''gets all records due to be paid
        Dim dt As DataTable
        'get the first payment \ contact back in a datatable. 
        'brings back all the parts of the payment, ie redress, d&i, hmrc deductions
        'and later concatenates them into one line
        dt = DataAccessLayer.FindRecords(listOfParam, _charterPayments, "dbo.usp_getFirstRecordForPayment")

        If dt.Rows.Count = 0 Then
            noRecords = True
            'if there are no records inform the user that there are no payments to be made this day. 
            ScriptManager.RegisterStartupScript(Me, GetType(Page), "noPayments", "$('#noPayments').modal();", True)
            Exit Sub
        End If

        'build a list of payments using a payee class 
        BuildListOfPayments(dt)

        'using MoreLINQ to get the First or Default record to get the most basic of information out. 
        Dim paymentInfo = listOfPayments.FirstOrDefault()


        ''if payment is an IVA, C&R or Deceased Case this will be thrown to the exceptions for manual handling. 
        If paymentInfo.isException = True Then
            'record the exceptions
            Dim recorded = RecordNewException(paymentInfo.ContactId, paymentInfo.ContactPartId, paymentInfo.ExceptionReason, True)
            If recorded = True Then
                'post the page back to get the next record and start the loop again
                Response.Redirect(Request.RawUrl, False)
                Context.ApplicationInstance.CompleteRequest()
            End If
        End If

        Try
            'set the class level variable 
            _PaymentCategory = paymentInfo.Category

        Catch ex As Exception
            Dim recorded = RecordNewException(paymentInfo.ContactId, paymentInfo.ContactPartId, "Cannot match complaint against a category type", True)
            If recorded = False Then
                Response.Redirect(Request.RawUrl, False)
                Context.ApplicationInstance.CompleteRequest()
            End If
        End Try
        'lock the record so that no other user can be working on this at the same time 
        LockRecord(dt)

        If paymentInfo.charterVersion = "GE" Then
            'if the payment is coming from GE Charter then complete various checks
            checkGeCharterPayments(paymentInfo)

        ElseIf paymentInfo.charterVersion = "SANUK" Then
            'if the payment is coming from GE Charter then complete various checks
            checkSanCharterPayments(paymentInfo)

        Else
            Exit Sub
        End If

    Catch sqlEx As SqlException
        PassToErrorHandler(sqlEx, System.Reflection.MethodInfo.GetCurrentMethod().ToString(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)

    Catch ex As Exception
        PassToErrorHandler(ex, System.Reflection.MethodInfo.GetCurrentMethod().ToString(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)
    End Try
End Sub

0 个答案:

没有答案