Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there any way of doing this..

Status
Not open for further replies.

tsisher

Programmer
Sep 14, 2004
36
GB
I have got two User controls

1) ListEmployee.ascx(Has got a DataGrid to list all the Employees and a View Button to show the Detail)

2) DetailEmployee.ascx(should display the employee list if pass a Employee ID)

Now I have got Two .aspx pages

1) ListEmployee.aspx (Which Has got ListEmployee.ascx control)
2) Detail.aspx (Which has got DetailEmployee.ascx control)

My question How can I pass the EmployeeID of ListEmployee.ascx from ListEmployee.aspx page to DetailEmployee.ascx in Detail.aspx page

Any help is realyyyyyyyy appreciated.
 
The ASP.NET has a global object called Session.
From MSDN: "Provides information to the current user session. Also provides access to a session-wide cache you can use to store information, along with the means to control how the session is managed."

The idea is that you can use this Session object as a hashtable like this:

In ListEmployee.ascx, when the user clicks the "Details" button:
Session[ "EmployeeID"] = m_CurrentlySelectedEmployeeID;

In DetailEmployee.ascx:

int m_iEmployeeID = Session[ "EmployeeID"] as int;
if( m_iEmployeeID == null)
{
//Something bad happened or the user typed directly the address of DetailEmployee.ascx in the address bar. Do whatever you want here, like redirect the user to the main page
}
else
{
//If you're here then you have the EmployeeID already. Proceed with execution...
}

It is a good thing to remove the object from Session before leaving this page, otherwise the Session object will become quite large (I met people which actually added large objects in the Session and forgot to remove them :) ). This can be done like this:

Session.Remove( "EmployeeID");

That's about all [2thumbsup]
 
Thanks a lot .
I'll try this and come back to you later.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top