Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在页面之间传递数据将加载以前的数据,直到页面刷新_Asp.net_Vb.net - Fatal编程技术网

Asp.net 在页面之间传递数据将加载以前的数据,直到页面刷新

Asp.net 在页面之间传递数据将加载以前的数据,直到页面刷新,asp.net,vb.net,Asp.net,Vb.net,我有一个按钮,当点击时,它会使用会话状态将数据传递到另一个页面,但它会在第一个加载实例上加载以前事务中的数据。刷新后,才会加载当前数据。我一直在寻找类似问题的解决方案,但我还没有找到一个能帮我解决这个问题的方案 按钮代码 Protected Sub LinkButton9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton9.Click 'LinkButton9.Attributes.

我有一个按钮,当点击时,它会使用会话状态将数据传递到另一个页面,但它会在第一个加载实例上加载以前事务中的数据。刷新后,才会加载当前数据。我一直在寻找类似问题的解决方案,但我还没有找到一个能帮我解决这个问题的方案

按钮代码

Protected Sub LinkButton9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton9.Click
    'LinkButton9.Attributes.Add("onclick", "window.open('waterprinter.aspx','','height=530,width=530');return false")
    'LinkButton9.Attributes.Add("onclick", "window.open('waterprinter.aspx', '','height=530,width=530','scrollbars=yes','tools=1');return false")


    Dim queryString As String = ""
    Dim SBRANCH As SqlDataReader
    Dim Pdate As Date
    Dim TRN As String = ""
    Dim PaymentFor As String = ""
    Dim CustomerName As String = ""
    Dim CustomerRef As String = ""
    Dim AmtDue As Double = 0
    Dim AmtPaid As Double = 0
    Dim ServedBy As String = ""
    Dim Branch As String = ""

    Try

        If Session("PayID") <> Nothing Then

            Dim MyReader As SqlDataReader
            Dim MyReaderI As SqlDataReader
            Dim MyReaderII As SqlDataReader
            MyReader = dat.DBAction("SELECT * FROM NSSFPaymentsArchive WHERE Authorized = 1 and Status = 'Posted' and PaymentID = " & Session("PayID") & "", DataManagement.DBActionType.DataReader)
            If MyReader.HasRows Then
                MyReader.Read()
                Session("TRN") = IIf(IsDBNull(MyReader("ReferenceNumber")), "", MyReader("ReferenceNumber")) '"50000.00"
                Session("PaymentFor") = IIf(IsDBNull(MyReader("PaymentName")), "", MyReader("PaymentName"))
                Session("Pdate") = FormatDateTime(Date.Today, DateFormat.ShortDate)
                Session("CustomerName") = IIf(IsDBNull(MyReader("CustomerName")), "", MyReader("CustomerName"))
                Session("CustomerRef") = IIf(IsDBNull(MyReader("CustomerRefNumber")), "", MyReader("CustomerRefNumber")) ' "Ura cash A/c"
                AmtDue = IIf(IsDBNull(MyReader("AmountDue")), "", MyReader("AmountDue")) ' "
                AmtPaid = IIf(IsDBNull(MyReader("AmountPaid")), "", MyReader("AmountPaid"))
                Session("AmtDue") = Format(Val(AmtDue - AmtPaid), "#,#.00")
                Session("AmtPaid") = Format(AmtPaid, "#,#.00")
                Session("PaymentOption") = IIf(IsDBNull(MyReader("PaymentOption")), "", MyReader("PaymentOption"))
                Session("Narration") = dat.SpellNumber(Val(AmtPaid), "Shilling")
                Session("Teller") = IIf(IsDBNull(MyReader("CapturedBy")), "", MyReader("CapturedBy"))
            Else
                MyReader.Close()
                MyReader = dat.DBAction("SELECT * FROM NSSFPayments WHERE  paymentid = " & Session("PayID") & "", DataManagement.DBActionType.DataReader)
                If MyReader.HasRows Then
                    MyReader.Read()
                    Session("TRN") = IIf(IsDBNull(MyReader("ReferenceNumber")), "", MyReader("ReferenceNumber")) '"50000.00"
                    Session("PaymentFor") = IIf(IsDBNull(MyReader("PaymentName")), "", MyReader("PaymentName"))
                    Session("Pdate") = FormatDateTime(Date.Today, DateFormat.ShortDate)
                    Session("CustomerName") = IIf(IsDBNull(MyReader("CustomerName")), "", MyReader("CustomerName"))
                    Session("CustomerRef") = IIf(IsDBNull(MyReader("CustomerRefNumber")), "", MyReader("CustomerRefNumber")) ' "Ura cash A/c"
                    AmtDue = IIf(IsDBNull(MyReader("AmountDue")), "", MyReader("AmountDue")) ' "
                    AmtPaid = IIf(IsDBNull(MyReader("AmountPaid")), "", MyReader("AmountPaid"))
                    Session("AmtDue") = Format(Val(AmtDue - AmtPaid), "#,#.00")
                    Session("AmtPaid") = Format(AmtPaid, "#,#.00")
                    Session("PaymentOption") = IIf(IsDBNull(MyReader("PaymentOption")), "", MyReader("PaymentOption"))
                    Session("Narration") = dat.SpellNumber(Val(AmtPaid), "Shilling")
                    Session("Teller") = IIf(IsDBNull(MyReader("CapturedBy")), "", MyReader("CapturedBy"))
                End If
            End If
            MyReader.Close()

            MyReaderI = dat.DBAction("select branchname from branches where solid='" & Session("branch") & "'", DataManagement.DBActionType.DataReader)
            If MyReaderI.HasRows Then
                MyReaderI.Read()
                Session("PayBranch") = MyReaderI("branchname")
            End If
            MyReaderI.Close()

            MyReaderII = dat.DBAction("select FULLNAME from USERS where USERNAME='" & Session("Teller") & "'", DataManagement.DBActionType.DataReader)
            If MyReaderII.HasRows Then
                MyReaderII.Read()
                Session("ServedBy") = MyReaderII("FULLNAME")
            End If
            MyReaderII.Close()


        End If

    Catch ex As Exception

    End Try
End Sub

任何帮助都将不胜感激。

我注意到它在单击按钮执行逻辑之前正在执行pageload逻辑。所以我把我在按钮点击上的逻辑放在另一个函数上,我在第二页的页面加载中调用了这个函数。我确保在第二页的页面加载之前调用了该函数,并且它工作正常。感谢您的贡献。

数据在加载第二页之前在DB中更新?不,而是在加载第二页之前从DB中获取数据。从哪里重定向到第二页?从该链接按钮9..单击该按钮..会重定向到第二页。我看不到任何重定向代码。此外,您可以重构代码,使用对象存储所有这些值,而不是单独设置它们。最后,能否附加第二页的load()方法?
    lblTRN.Text = Session("TRN")
    lblPaymentFor.Text = Session("PaymentFor")
    lblPaymentDate.Text = Session("Pdate")
    lblCustomerName.Text = Session("CustomerName")
    lblCustomerRefNo.Text = Session("CustomerRef")
    lblAmountDue.Text = Session("AmtDue")
    lblAmountPaid.Text = Session("AmtPaid")
    lblServedBy.Text = Session("ServedBy")
    lblBank.Text = "IMPERIAL BANK"
    lblBranch.Text = Session("Branch")
    Label2.Text = Session("Narration")


End Sub