Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:05:07+00:00 2026-06-12T04:05:07+00:00

I am using ASP.NET. I have a ReportPage1 and ReportOutputPage1. These are different aspx

  • 0

I am using ASP.NET. I have a ReportPage1 and ReportOutputPage1. These are different aspx files and has different MasterPages. However, I need the same SqlDataSource object to use on both pages. On ReportPage I need SqlDataSource to call StoredProcedure and import data to CSV file, but on ReportOutputPage I need to use SqlDataSource to call the same StoredProcedure and populate GridView.

ReportPage1 is “main” page – a button click from this page opens ReportOutputPage1 and displays it in new window. ReportPage is PreviousPage for ReportOutputPage1.

Above is example for Report1. The same idea is for Report2 (with SqlDataSource2) and for Report3 (SqlDataSource3) etc. – 10 different reports.

How to reuse SqlDataSource for every two pages (ReportPage & ReportOutputPage)?

  1. First suggestion I found in web – using masterpage for both ReportPage and ReportOutputPage. This doesn’t work, as I have already have different masterpages for ReportPage and ReportOutputPage, as well as then I need to create 10 different MasterPages for each Report.

  2. Second suggestion was to define SqlDataSource on ReportPage and then reuse it using PrevousePage on ReportOutputPage, but this doesn’t work for my special case (I am using Ajax staff and Partial page postbacks and I am loosing PreviousPage, also SqlDataSource could not be serialized to save it in ViewState or similar).

  3. Create UserControl. Probably this could work, but it is time consuming to create UserControl every time for new Report (10 reports – 10 usercontrols?).

  4. Simply Copy & Paste SqlDataSource (I did it for one Report) could work, but I would like something more like code reuse. Someone could simply forget to modify SqlDataSource in two different places if necessary.

Can you, please, give me some suggestions how to reuse code (particularly, SqlDataSource) for Report & ReportOutput pages?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:05:09+00:00Added an answer on June 12, 2026 at 4:05 am

    Could you define the need for using the same SqlDataSource? If they are two different pages and it sounds like two different uses why not use two different SqlDataSource? The pages are separate anyhow, your not going to be able to share an object on one with the other.

    I would suggest you look at adding a data layer to your application for database interaction and binding your data to the datagrid at request time. That way you build your database interaction once and reuse that over different pages.

    The other option is you simply use two SqlDataSources and copy/paste them to both the pages. If your trying to make a selection or some sort of criteria apply to your second page then consider using query strings and QueryStringParameters in your SqlDataSource.

    Hope this helps.

    Edit: Pop this in App_Code somewhere, pass in your specific usage requirements.

    Public Shared Function GetData(connString As String, command As String, Optional params As SqlParameter() = Nothing) As DataTable
        Dim conn As New SqlConnection(connString)
        Dim da As New SqlDataAdapter(command, conn)
        Dim dt As New DataTable
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        da.SelectCommand.CommandTimeout = 6000 '6 seconds.
        If Not IsNothing(params) Then
            For Each p As SqlParameter In params
                da.SelectCommand.Parameters.Add(p)
            Next
        End If
        Try
            conn.Open()
            da.Fill(dt)
            Return dt
        Catch ex As Exception
            Throw ex
        Finally
            conn.Close()
        End Try
    End Function
    

    Then bind the datatable to your gridview, not sure how your outputing to file.

    Private Sub BindData(gridview As GridView, data As DataTable)
        gridview.DataSource = data
    End Sub
    

    You can now re-use the database interaction from the code behind:

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
       BindData(MyGridView,GetData(ConnectionStrings(connName).ConnectionString, _
                     "dbo.SomeSprocOrOther", _
                     New SqlParameter(){New SqlParameter("paramName","paramValue")})
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ASP.NET MVC and have a model which has an image (byte array)
I have created a website using asp.net and I have created some resource files
Using asp.net, c# 3.5, vs 2008. I have an aspx gridview called gv1 with
I am using asp.net Mvc3 I have 2 controllers in two different projects. HomeController
I have a list of drop down lists populated form a database(using ASP.NET). These
We have been using asp.net mvc for development. Sometimes, we need to put some
sending mail along with embedded image using asp.net I have already used following but
I'm using ASP.NET and I have a string of HTML in the database. I
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />
Using ASP.NET MVC 2.0, I have an actionlink that is used for comments on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.