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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:06:13+00:00 2026-06-14T09:06:13+00:00

I have following code in aspx page: <asp:ObjectDataSource id=odsOuterSource TypeName=my.namespace.page SelectMethod=GetTestObject DataObjectTypeName=my.namespace.Entities.TestObject /> <asp:ObjectDataSource

  • 0

I have following code in aspx page:

<asp:ObjectDataSource id="odsOuterSource" TypeName="my.namespace.page"
SelectMethod="GetTestObject" DataObjectTypeName="my.namespace.Entities.TestObject" />

<asp:ObjectDataSource id="odsInnerSource" TypeName="my.namespace.page"
SelectMethod="GetAnotherTestObject" 
DataObjectTypeName="my.namespace.Entities.AnotherTestObject" />

and following code in code-behind:

public TestObject GetTestObject()
{
    Logic myLogic = new MyLogic();
    return myLogic.GetTestObject();
}

public AnotherTestObject GetAnotherTestObject()
{
    Logic myLogic = new MyLogic();
    return myLogic.GetAnotherTestObject(testObject);
}

Now my question is if there is a way to get the TestObject which was returned by the OuterSource so that I could use it for the InnerSource without having to call GetTestObject again.

I hope you can help me with this.

Edit: For better readability than a comment

Thanks for your answers, but i have a question to Mudu’s answer:

Is there a way to do this if my OuterSource has a parameter?
For example

<asp:ObjectDataSource id="odsOuterSource" TypeName="my.namespace.page"
SelectMethod="GetTestObject" DataObjectTypeName="my.namespace.Entities.TestObject">
    <SelectParameters>
        <asp:QueryStringParameter Name="id" QueryStringField="id" DefaultValue="0" />
    </SelectParameters>
</asp:ObjectDataSource>

because then even my GetTestObject would have a parameter:

public TestObject GetTestObject(int id)
{
    Logic myLogic = new MyLogic();
    return myLogic.GetTestObject(id);
}
  • 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-14T09:06:15+00:00Added an answer on June 14, 2026 at 9:06 am

    You could save it in a member, either as TestObject or as a Lazy<TestObject>:

    private readonly Lazy<TestObject> myTestObject = new Lazy<TestObject>(() =>
    {
        var myLogic = new MyLogic();
        return myLogic.GetTestObject();
    });
    

    With this code, you can receive it any number of times you want. It will be fetched via MyLogic once and re-returned on subsequent invocations:

    public TestObject GetTestObject()
    {
        return this.myTestObject.Value;
    }
    
    public AnotherTestObject GetAnotherTestObject()
    {
        var testObject = this.myTestObject.Value; // re-used
    
        Logic myLogic = new MyLogic();
        return myLogic.GetAnotherTestObject(testObject);
    }
    

    As ASP.NET creates a new instance of your page for each request, the Lazy<TestObject> object is recreated for each request. Therefore, your TestObject is actually fetched once per request.

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

Sidebar

Related Questions

I am using ASP.NET and in my .aspx page I have the following code,
I have the following code in my aspx page: <asp:Button runat=server ID=myButton Text=hello />
I have following code. ASPX Page <a href=AnyASPXPageOfWebsite.aspx onclick=javascript:CallJQuery(); > Set Price </a> JS
Morning stackoverflow, I have a repeater, with the following code in my aspx page;
I have an ASP.NET web site with something similar to the following code: .aspx
i've the following code in aspx page <asp:Label ID=CittaLabel runat=server Text='<%# Eval(Citta) %>' Font-Size='<%#
I have following simple code: <%@ Page Language=C# AutoEventWireup=true CodeBehind=testForm.aspx.cs Inherits=Orbs.testForm %> <html> <body>
I have the following code on my Home.aspx page: <form id=frmJump method=post action=Views/ViewsHome.aspx> <input
I have the following button on a .aspx page: <asp:Button runat=server ID=bntLogin OnClick=bntLogin_Click Text=Login
I have a problem with the following code in an ASPX page: <script type=text/javascript>

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.