Sessions and User Controls

Vetrijar

Regular
Joined
Sep 1, 2003
Messages
55
Location
Texas
I'm a little lost on sessions right now.

I can use a session in my aspx project and access the
session through other aspx pages in the project.
With a user control, I cannot change or access sessions
made WITHIN the control. just ones outside of the
control itself. Along with this, ones outside of the control
that are in an aspx page I can only access, not change its
value.

Is this the way sessions work??
 
no, I don't think it's accessing that way.

Here's some coding

Visual Basic:
    Private Sub rb_Country_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rb_Country.SelectedIndexChanged
        ' Update country connections

        If rb_Country.SelectedItem.Value = "Select Country" Or Trim$(rb_Country.SelectedItem.Value) = "" Then
            lblLocation.Visible = False
            rb_location1.Visible = False
            rb_location1.Text = "" ' Clear 
            rb_Location2.Visible = False
            Session("Country") = "00"
        ElseIf rb_Country.SelectedItem.Value = "US" Then
            ' United States
            lblLocation.Visible = True
            rb_location1.Visible = True
            rb_Location2.Visible = False
            rb_location1.Text = "" ' Clear 
            lblLocation.Text = "Zipcode"
            Session("Country") = "US"
        Else
            ' Some other country
            FillParts(rb_Country.SelectedValue)
            Session("Country") = rb_Country.SelectedValue
            rb_Location2.Visible = True
            rb_Location2.SelectedIndex = 0 ' Reset
            lblLocation.Visible = True
            rb_location1.Visible = False
            rb_location1.Text = "" ' Clear 
            lblLocation.Text = "Location"
        End If
        lblError.Visible = False
    End Sub
The above code is what SHOULD run after the selection box is used. the autopostback is on also.


I load the usercontrol through an aspx like this

Visual Basic:
    Private Sub btnAccountProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccountProfile.Click
        lblWait.Visible = True
        Dim Ctrl As UserControl

        ServiceHolder.Controls.Clear()
        If Session("AccountType") = "Couple" Then
            Ctrl = LoadControl("Controls/cprofileeditor.ascx")
            CType(Ctrl, cprofileeditor).SetControl(User.Identity.Name)
        Else
            Ctrl = LoadControl("Controls/profileeditor.ascx")
            CType(Ctrl, profileeditor).SetControl(User.Identity.Name)
        End If

        ServiceHolder.Controls.Add(Ctrl) ' load from memory

When I try to access the Session("Country") in the usercontrol. the session is always the first setting it had (mainly empty)
whether it's displaying the session on the screen, or using it otherwise.
 
Back
Top