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 6237127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:58:12+00:00 2026-05-24T10:58:12+00:00

as the title said is SqlDataSource can be shared across different aspx page? i

  • 0

as the title said is SqlDataSource can be shared across different aspx page?
i have exact same sqldatasource on multiple aspx page, is it possible to create one and shared for all the pages.

thanks

  • 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-05-24T10:58:14+00:00Added an answer on May 24, 2026 at 10:58 am

    Sure. If you really mean shared, as in all pages use the same SqlDataSource, create a Master Page and put the data source in the master. In the codebehind, expose it as a property of the master. From there, you can reference it from any page that uses the Master.

    Second option – create a base Page class:

    public class MyPage : Page
    {
          private SqlDataSource mDataSource;
    
          public override void OnLoad(EventArgs e)
          {
               base.OnLoad(e);
               // some code to init your data source - depending on your
               // implementation, this may need to be in OnInit instead
          }
    
          public SqlDataSource DataSource 
          { 
               get { return mDataSource; } 
          }
    }
    

    In this case, any time you create a new page, go to the code behind and change the declaration from implementing Page to MyPage. All pages that implement MyPage will have an SqlDataSource member, though each would have its own instance, so that’s not really “sharing” the same SqlDataSource.

    Either option gets you where you want to go I think.

    UPDATE: Poster requested an example of exposing in as a property of the master:

    Given a Master Page with the following:

    <asp:SqlDataSource runat="server" ID="mDataSource" ... the rest of your properties .... />
    <asp:ContentPlaceHolder runat="server" ID="MainContent"/>
    

    In the code-behind for the master, define the property:

    public class SiteMaster : System.Web.UI.MasterPage
    {
        public SqlDataSource MasterDataSource
        {
             get { return mDataSource; }
        }
    
        // the rest of your master page's codebehind
    }
    

    In the pages you define for using your master page, add the following below the @Page declaration:

    <%@ MasterPage VirtualPath="~/site.master"%>
    

    Now, in the codebehind for that page, you can reference:

    protected void Page_Load(object sender, EventArgs e)
    {
         SqlDataSource ds = this.Master.MasterDataSource;
    }
    

    As long as you have as long as you have a <%@ MasterType VirtualPath=”~/ PATH TO YOUR MASTER” %> in your aspx page, you can reference any properties you expose in the master.

    Happy coding.

    B

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title said: Is it possible to send an email (using php mail())
As said in the title: How can I change my php server settings so
Title said it all. im just wandering if there something i can use in
Like the title said, .load() function won't load javascript from called page. Would be
Like I said in the title, I was wondering whether it would be possible
as i said in my title am learning about Ajax and i have a
I'm not sure how to title the question I have so I can't be
As title said, I have C program complied and created a binary in 64-bit
Same as Title said: What is the benefit for freeze gems in Ruby on
as the title said i would like to create a button that says available

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.