Hello,
If the listbox is in the usercontrol then you need to make a public property
on the usercontrol that you use to set the selectedItem property of the
listbox in the user control. Like this:
In your usercontrol do this:
Public Class WebUserControl1
Inherits System.Web.UI.UserControl
Protected WithEvents listbox1 As ListBox
Private m_selectedValue As String = String.Empty
Public Property SelectedValue() As String
Get
Return m_selectedValue
End Get
Set(ByVal Value As String)
m_selectedValue = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Load you listbox here
For Each item As ListItem In listbox1.Items
If item.Value = m_selectedValue Then
item.Selected = True
Exit For
End If
Next
End Sub
End Class
Now in your web page you can set the seletedValue property like this:
Protected WithEvents myUserControl As WebUserControl1 'This is your
usercontrol
'This code goes in the Page_Load event
yourUserControl.SelectedValue = Session("MySessionKey")
I would stay way from using the session state for something like this. You
find that a querystring would work better in this situation.
Let me know if you have any questions.