how do I access an instantiated object from a 2nd page C#

In Default.asp.cs, I have:
public partial class _Default : System.Web.UI.Page
{
    MyCriteria mc =new MyCriteria();

    protected void Page_Load(object sender, EventArgs e)
    {

        mc.PressedMaster="abc";
        mc.YYYY="2013";
   }
}

Open in new window

Now, I want to access it from Page1.asp.cs:
public partial class _Page1 : System.Web.UI.Page
{
    //MyCriteria mc =new MyCriteria();

    protected void Page_Load(object sender, EventArgs e)
    {

       // mc.PressedMaster="abc";
       // mc.YYYY="2013";
   }
}

Open in new window

Question: How can I read "2013" value stored in YYYY property before in Default.asp.cs?

Is it possible without use of session variable?

Thank you.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
 
MrunalCommented:
One way is put that object in session if these varies for user to user and access that same session in another page.

Another way is create public property in page1 and assign value to that property from default page.

Hope this helps you.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
re:> Another way is create public property in page1 and assign value to that property from default page.

This is my question. How to do this.
0
 
MrunalCommented:
okay.

In page1, add below code:

public MyCriteria MyCriteriaObject { get; set; }

Open in new window


From Default page, access this property and set the value.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Mrunal,

re:> From Default page, access this property and set the value.

As you can see above, I am accessing the properties of the object in Default page. Therefore, accessing it from Default page is not the issue. The question is how to access the same object created in the Default.aspx.cs earlier from Page1.aspx.cs .

I appreciate if you plug your solution in the code below:
public partial class _Page1 : System.Web.UI.Page
{
    //MyCriteria mc =new MyCriteria();

    protected void Page_Load(object sender, EventArgs e)
    {

       // mc.PressedMaster="abc";
       // mc.YYYY="2013";
   }
}

Open in new window


Thanks,

Mike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.