locked
RDLC report Issue with Recursive Code Behind RRS feed

  • Question

  • User-305496339 posted

    Hi Guys,

    I am working on opening a rdlc in  reportviewer from another form using vb.net webforms using a stored procedure that takes three parameters. I have included the code as far as my issue is concerned where I was wondering is there something I need to include to stop the code that opens the reportviewer from once it reaches the end of the procedure in the form load event  calling the load event  again. I don't understand why it's doing this. Thanks Guys I really need your help with this one. Thank You !!!

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            Dim endddate As String = Now.ToString("MM/dd/yyyy")
            If Request.QueryString("enddate") IsNot Nothing OrElse IsDate(Request.QueryString("endddate")) Then
                endddate = Request.QueryString("enddate")
            End If
    
            Dim startdate As String = CDate(endddate).AddDays(-1)
            If Request.QueryString("startdate") IsNot Nothing OrElse IsDate(Request.QueryString("startdate")) Then
                startdate = Request.QueryString("startdate")
            End If
    
            If (DateDiff(DateInterval.Day, CDate(startdate), CDate(endddate))) < 0 Then
                startdate = CDate(endddate).AddDays(-1)
            End If
    
            If (DateDiff(DateInterval.Year, CDate(startdate), CDate(endddate))) > 5 Then
                startdate = CDate(endddate).AddYears(-5)
            End If
    
            Dim EmailFlag = CType(Request.QueryString("EmailFlag"), EmailBatchFlag)
            Dim EmailFlagDdl As String
            Dim EmailFlagTxt As String
            If (Request.QueryString("EmailFlag") IsNot Nothing) Then
                EmailFlagDdl = IIf(EmailFlag = 1, "X", "A")
                EmailFlagTxt = IIf(EmailFlag = 1, "Delinquent", "Accessed")
            Else
                EmailFlagDdl = "X"
                EmailFlagTxt = "Delinquent"
            End If
            Dim dt As DataTable = GetSPResult()
            ReportViewer1.Visible = True
            ReportViewer1.LocalReport.ReportPath = "Report.rdlc"
            ReportViewer1.LocalReport.DataSources.Clear()
            Dim rds = New ReportDataSource("DataSet1", dt)
            ReportViewer1.LocalReport.DataSources.Add(rds)
        End Sub
    

    Public Function GetSPResult() As DataTable Dim ResultsTable As DataTable = New DataTable() Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("EzTaxExpressConnectionString").ConnectionString) Try Dim cmd As SqlCommand = New SqlCommand("[oesc_BusinessInformation].[getSentEmail]", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@StartDate", Request.QueryString("startdate")) cmd.Parameters.AddWithValue("@EndDate", Request.QueryString("enddate")) cmd.Parameters.AddWithValue("@BatchFlag", "X") Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmd) adapter.Fill(ResultsTable) Catch ex As Exception Response.Write(ex.ToString()) Finally If conn IsNot Nothing Then conn.Close() End If End Try Return ResultsTable End Function



    Wednesday, June 3, 2020 5:14 PM

Answers

  • User475983607 posted

    There is nothing in the posted code that would cause the page to load multiple times.  The issue must be in the code that calls this page. 

    Also, the code shown has questionable logic.  The page_Load validates querystring values but the GetSpResults ignore the validation and grabs the querystring values directly.

    Form the looks of your code and the problem statement, I think you need to spend more time debugging your code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 3, 2020 6:25 PM
  • User475983607 posted

    I still do not see any code that would cause multiple HTTP request to Viewer.aspx. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 3, 2020 7:59 PM

All replies

  • User475983607 posted

    There is nothing in the posted code that would cause the page to load multiple times.  The issue must be in the code that calls this page. 

    Also, the code shown has questionable logic.  The page_Load validates querystring values but the GetSpResults ignore the validation and grabs the querystring values directly.

    Form the looks of your code and the problem statement, I think you need to spend more time debugging your code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 3, 2020 6:25 PM
  • User-305496339 posted

    Thanks for your help !!! I have attached the code from the form that calls the above code in the form thats loading and will subsequently display the report. Maybe using "response.redirect" is the problem. And to respond to one of your comments. Yes I did hard code one of the parameters because I need to get some more clarity....I didnt write that code so I need a better understanding of the use case. But again Thanks for your help and please see the attached code. 

    Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
    
    
    
            Response.Redirect("Viewer.aspx?startdate=" + StartDateTxt.Text + "&enddate=" + EndDateTxt.Text + "&EmailFlag=" + EmailFlagDdl.SelectedValue)
    End Sub

    Wednesday, June 3, 2020 7:37 PM
  • User475983607 posted

    I still do not see any code that would cause multiple HTTP request to Viewer.aspx. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 3, 2020 7:59 PM