I want to pass for example to instance of my employee class to the next page ,
I use CONTEXT
CONTEXT>ITEMS>ADD. ....
and then SERVER>TRANSFER();

but it doesn`t work properly and if i set the properties of these instances to the same class objects in the next page I get:

Object reference not set to an instance of an object

why? I sometimes can use their properties for example in the next page textboxes , but i couldn`t really find a rule for that , it doesn`t usually work

CAN I USE OTHER THINGS RATHER THAN CONTEXT?
if yes pleas show me the code,
I USE C# CODE

use session, profile object....works...

hope it helps..!

Suppose I havv two forms Default3.aspx & Default4.aspx,I m passing the values from Default3.aspx to Default4.aspx-

First method-
Passing values using Query String Method-

Default3.aspx 

 protected void Button2_Click(object sender, EventArgs e)
    {
        
        Response.Redirect("Default4.aspx?username=" + TextBox1.Text +  "&PASSWORD=" + TextBox2 .Text );
    }

Default4.aspx 
protected void Page_Load(object sender, EventArgs e)
    {
       
        Response.Write(Request["username"]);
        Response.Write(Request["password"]);
    }

Second Method
passing values using Session Method

Default3.aspx 
protected void Button1_Click(object sender, EventArgs e)
    {
        Session["NAME"] = TextBox1.Text;
        Response.Redirect("Default4.aspx");
    }

Default4.aspx

 protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Session["Name"]);
       
    }

hey dnanetwork, can u plz telll me what is profile object???

Secondly,tell me one thing is it necessary to match case while passing values means username & USERNAME are same

Hi,

If Profile object is used, then we need to use SQL Server. Because Profile data will be stored in SQL Server. Also basically Profile object is used to web site personalization.

I would recommend Session to pass custom objects between pages.

To store an object to sesssion

Employee emp = new Employee();
emp.Ename = txtEname.Text;
emp.Empno = int.Parse(txtEmpNo.Text);
emp.Salary = double.Parse(txtSal.Text);
...
...
...
Session["Emp"] = emp;

To retrieve Employee object from Session

Employee emp = (Employee)Session["Emp"];
txtEname.Textc = emp.Ename ;
txtEmpNo.Text = emp.Empno.ToString();
txtSal.Text = emp.Salary.ToString();

yes you are correct ramesh...thank you for correcting me..

hey tell me one thing,when we need to use profile object......I thk so its hardly use,cz we have session to pass data between pages....

To persist a state of an object between requests you may use:

  1. Client side state management
    • Cookies - String datatype only
    • ViewState - Any datatype (serializable)
    • Hidden Fields - String type
    • Query Strings - String type
  2. Server side state management
    • Session - Any datatype (serializable)
    • Profile - Any datatype (serializable)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.