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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:09:59+00:00 2026-05-16T02:09:59+00:00

How to pass a class into another class to a codebehind? When I debug

  • 0

How to pass a class into another class to a codebehind?

When I debug and check the myCategoryObj in the Default.aspx page, I can see the object is in the debug. What am I doing wrong?

I know I could create the object in the Default.aspx but I should not have to I should be able to call the Business Logic Layer and ask for an object back and then fill the object and pass it back to the Business Logic Layer to be saved (insert or update).

I hope this makes sense.

Default.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SC1.Models.OBJ;
using SC1.Models.BLL;
using SC1.Models.DAL;

namespace SC1
{
  public partial class Default : System.Web.UI.Page
  {
    protected void Page_Load(Object sender, EventArgs e)
    {
      // I know I could do this but I don't want to unless I have too.
      //Category categoryObj = new Category();

      CategoryBLL myCategoryBLL = new CategoryBLL();

      Object myCategoryObj = myCategoryBLL.CategoryNew();

      // How do I make the code below work or what am I doing wrong.  
      myCategoryObj.Name = "test";

      string test = "";

    }
  }
}

CategoryBLL.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using SC1.Models.DAL;
using SC1.Models.OBJ;

namespace SC1.Models.BLL
{
  public class CategoryBLL
  {
    // Create a page object
    Category myCategoryObject = new Category();

    // Create a Data Acces Layer Object
    CategoryDAL myCategoryDAL = new CategoryDAL();


    public CategoryBLL()
    {
    }

    public DataSet Select()
    {
      return (myCategoryDAL.Select());
    }

    public Object CategoryNew()
    {
      return myCategoryObject;
    }



  }
}

CategoryDAL.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace SC1.Models.DAL
{
  public class CategoryDAL
  {
    public CategoryDAL()
    {
    }
    string connStr = ConfigurationManager.ConnectionStrings["staceys_cakesConnectionString"].ConnectionString;

    // select all
    public DataSet Select()
    {
      SqlConnection sqlConnection1 = new SqlConnection();
      string SqlString = "select * from Categories";
      SqlDataAdapter da = new SqlDataAdapter(SqlString, connStr);
      DataSet ds = new DataSet();
      da.Fill(ds, "Categories");
      return (ds);
    }
    // save
    // insert
    // update
    // delete

  }
}

Category.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SC1.Models.OBJ
{
  public class Category
  {
    public int CategoryID { get; set; }
    public int ParentID { get; set; }
    public string Name { get; set; }
    public int DisplayOrder { get; set; }
    public bool Active { get; set; }

    public Category(){
    }

  }
}
  • 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-16T02:09:59+00:00Added an answer on May 16, 2026 at 2:09 am

    change

    Object myCategoryObj = myCategoryBLL.CategoryNew()
    

    to

    Category myCategoryObj = myCategoryBLL.CategoryNew()
    

    and also

    public Object CategoryNew()
    {
    return myCategoryObject;
    }

    to

    public Category CategoryNew()
    {
    return myCategoryObject;
    }

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

Sidebar

Related Questions

You can pass special strings into jQuery's Datepicker class setDate() method like +7 which
I pass a data access class (DAL) of my own making into a another
Im attempting to pass an array that is created in one class into another
Is there a way to pass a class into a property as a Class
Here I only want to pass a custom class or only parameters into a
How do I grab the Type of the inherited class and pass it into
I would like to pass values into the constructor on the class that implements
I am trying to pass Array from one class to another I used detailViewController.nameArray
I need to pass a function into another function and call it there. I
i have been attempting to pass an object into a function that belongs to

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.