I am having the same problem. My controls are definetly being recreated on postback and the button ID's are not changing...
Is there anything else that could be the problem as my event is not getting fired..
Code:
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.IO
Imports System.Web.Security
Imports ProjectNexus.ApplicationTier.UserManagement
Namespace Controls
<System.Web.UI.ParseChildren(True), _
System.Web.UI.ToolboxData("<{0}:NavigationMain runat=server></{0}:NavigationMain>")> _
Public Class NavigationMain
Inherits System.Web.UI.Control
Implements INamingContainer
Private _user As Objects.User = Nothing
Private _objTable As Web.UI.WebControls.Table
Protected ReadOnly Property SiteUser() As Objects.User
Get
Return _user
End Get
End Property
Protected ReadOnly Property Entity() As ApplicationTier.UserManagement.Enumerations.Entity
Get
If SiteUser Is Nothing Then
Dim e As ApplicationTier.UserManagement.Enumerations.Entity
e = CType(System.Web.HttpContext.Current.Session("Entity"), ApplicationTier.UserManagement.Enumerations.Entity)
If IsNothing(e) Then
Return ApplicationTier.UserManagement.Enumerations.Entity.Student
Else
Return e
End If
Else
Return _user.Type
End If
End Get
End Property
Private Property SelectedRealm() As Enumerations.Realms
Get
Return CType(System.Web.HttpContext.Current.Session("SelectedRealm"), Enumerations.Realms)
End Get
Set(ByVal Value As Enumerations.Realms)
System.Web.HttpContext.Current.Session("SelectedRealm") = Value
End Set
'TODO: Reset session vALUE when left navigation clicked
End Property
Public Sub New()
' Attempt to get the current user
Me._user = AppInstance.ManagerFactory.UserManager.GetLoggedOnUser
' Is the user not availabe - must be anonymous
If Me._user Is Nothing Then
AppInstance.ManagerFactory.UserManager.TrackAnonymousUsers()
End If
End Sub 'New
Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
'Setup Table
_objTable = New Web.UI.WebControls.Table
_objTable.ID = "Table"
Me.Controls.Add(_objTable)
End Sub 'CreateChildControls
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
_objTable.ID = "MainNavTable"
_objTable.CellPadding = 0
_objTable.CellSpacing = 0
BuildRealmRow()
BuildRealmSpacerRow()
_objTable.RenderControl(writer)
End Sub
Private Sub AddSpacerCell(ByVal row As TableRow, ByVal BGColor As System.Drawing.Color)
Dim Cell As TableCell
Dim Image As New HtmlControls.HtmlImage
Image.Src = Settings.Site.ApplicationVRoot & "/Imgz/spacer.gif"
Image.Width = 5
Cell = New TableCell
If Not IsNothing(BGColor) Then
Cell.BackColor = BGColor
End If
Cell.Controls.Add(Image)
row.Cells.Add(Cell)
End Sub
Private Sub BuildRealmRow()
Dim Cell As TableCell
Dim Row As TableRow
Row = New TableRow
'Setup navigation Realms
Dim Realms() As String = Settings.Navigation.Realms(Entity)
System.Web.HttpContext.Current.Trace.Write("NavigationMain", Tools.Strings.ArrayToString(Realms))
For i As Integer = 0 To Realms.Length - 1
Dim objRealm As New FormElements.RolloverTab
objRealm.ID = Realms(i)
objRealm.Key = Realms(i) & "Tab"
objRealm.ResourseType = Helpers.Resourses.ResourseType.EnitySpecific
objRealm.MouseDown = True
objRealm.RollOver = True
objRealm.CommandName = Realms(i)
'objRealm.EnableViewState = False
AddHandler objRealm.Click, AddressOf Realm_Click
System.Web.HttpContext.Current.Trace.Write("NaviagationMain:ButtonCreated", Realms(i))
Cell = New TableCell
Cell.Controls.Add(objRealm)
Row.Cells.Add(Cell)
'Add spacer if nessesery
If Not i = Realms.Length - 1 Then
AddSpacerCell(Row, Nothing)
End If
Next
_objTable.Rows.Add(Row)
End Sub
Private Sub BuildRealmSpacerRow()
Dim Cell As TableCell
Dim Row As TableRow
Row = New TableRow
'Setup row spacer for Realms
Dim Realms() As String = Settings.Navigation.Realms(Entity)
For i As Integer = 0 To Realms.Length - 1
If SelectedRealm.ToString = Realms(i) Then
Dim Realm_Color() As String = Settings.Navigation.Realm_Colors(Entity)
AddSpacerCell(Row, System.Drawing.ColorTranslator.FromHtml(Realm_Color(i)))
Else
AddSpacerCell(Row, Nothing)
End If
If Not i = Realms.Length - 1 Then
AddSpacerCell(Row, Nothing)
End If
Next
_objTable.Rows.Add(Row)
End Sub
Private Sub Realm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim But As FormElements.RolloverTab = CType(sender, FormElements.RolloverTab)
System.Web.HttpContext.Current.Trace.Write("NavigationMain:CommandName", But.CommandName)
SelectedRealm = CType([Enum].Parse(GetType(Enumerations.Realms), But.CommandName), Enumerations.Realms)
End Sub
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If Not IsNothing(SelectedRealm) Then
Dim objRealm As FormElements.RolloverTab = CType(Me.FindControl(SelectedRealm.ToString), FormElements.RolloverTab)
If Not objRealm Is Nothing Then
objRealm.Selected = True
End If
End If
End Sub
End Class
End Namespace