UserControl.Session Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
HttpSessionState Mendapatkan objek untuk permintaan Web saat ini.
public:
property System::Web::SessionState::HttpSessionState ^ Session { System::Web::SessionState::HttpSessionState ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.SessionState.HttpSessionState Session { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Session : System.Web.SessionState.HttpSessionState
Public ReadOnly Property Session As HttpSessionState
Nilai Properti
Objek HttpSessionState yang Page terkait dengan yang berisi UserControl instans.
- Atribut
Contoh
Contoh berikut menambahkan nilai ke Session properti kontrol pengguna. Sintaks myControl.Session.Add menyisipkan nilai dua TextBox kontrol server Web ke sesi yang terkait dengan kontrol pengguna dan halaman yang berisinya.
// Save state information which is used by display handler after the postback has occurred.
void SubmitBtn_Click(Object sender, EventArgs e)
{
// Clear all values from session state of 'Page'.
Session.Clear();
// Populate Session State of UserControl with the values entered by user.
myControl.Session.Add("username",myControl.user.Text);
myControl.Session.Add("password",myControl.password.Text);
// Add UserControl state to the SessionState object of Page.
Session[myControl.user.Text]= myControl;
display.Enabled = true;
}
void Display_Click(Object sender, EventArgs e)
{
int position = Session.Count - 1;
// Extract stored UserControl from the session state of page.
LogOnControl tempControl = (LogOnControl)Session[Session.Keys[position]];
// Use SessionState of UserControl to display previously typed information.
txtSession.Text = "<br /><br />User:" + tempControl.Session["username"] + "<br />Password : " + tempControl.Session["password"];
display.Enabled = false;
}
' Saves state information which is used by display handler after the postback has occurred.
Sub SubmitBtn_Click(Sender As Object, e As EventArgs)
' Clear all values from session state of 'Page'.
Session.Clear()
' Populate Session State of UserControl with the values entered by user.
myControl.Session.Add("username",myControl.user.Text)
myControl.Session.Add("password",myControl.password.Text)
' Add UserControl state to the SessionState object of Page.
Session(myControl.user.Text)= myControl
Display.Enabled = true
End Sub
Sub Display_Click(Sender As Object,e As EventArgs)
Dim position As Integer = Session.Count - 1
' Extract stored UserControl from the session state of page.
Dim tempControl As LogOnControl = CType(Session(Session.Keys(position)),LogOnControl)
' Use SessionState of UserControl to display previously typed information.
txtSession.Text = "<br /><br />User:" + tempControl.Session("username") + "<br />Password : " + tempControl.Session("password")
Display.Enabled = false
End Sub