UserControl.Session Property
.NET Framework 3.0
Gets the HttpSessionStateobject for the current Web request.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
/** @property */ public HttpSessionState get_Session ()
public function get Session () : HttpSessionState
Not applicable.
Property Value
An HttpSessionState object associated with the Page that contains the UserControl instance.The following example adds values to the Session property of a user control. The myControl.Session.Add syntax inserts the values of two TextBox Web server controls to the session associated with the user control and the page that contains it.
// Save state information which is used by display handler after the
// postback has occured.
void SubmitBtn_Click(Object sender, EventArgs e)
{
// Clear all values from session state of 'Page'.
get_Session().Clear();
// Populate Session State of UserControl with the values entered by user.
myControl.get_Session().Add("username",myControl.user.get_Text());
myControl.get_Session().Add("password",myControl.password.get_Text());
// Add UserControl state to the SessionState object of Page.
get_Session() .set_Item( myControl.user.get_Text() , myControl );
display.set_Enabled(true);
} //SubmitBtn_Click
void Display_Click(Object sender, EventArgs e)
{
int position = get_Session().get_Count() - 1;
// Extract stored UserControl from the session state of page.
LogOnControl tempControl = (LogOnControl)(get_Session().get_Item(
get_Session().get_Keys().get_Item(position)));
// Use SessionState of UserControl to display previously typed
// information.
txtSession.set_Text("<br /><br />User:"
+ tempControl.get_Session().get_Item("username") + "<br />Password : "
+ tempControl.get_Session().get_Item("password"));
display.set_Enabled(false);
} //Display_Click
Community Additions
ADD
Show: