Yes, it's the infamous viewstate again!
Now I am aware that problems can ocurr if you load controls in the wrong order or if the viewstate IDs are incorrect after postbacks etc etc.
But my issue is that I am not really creating any controls dynamically - I only have one user control on the page.
More importantly, the issue seems to be occuring with just one user.
What could be the problem? Corrupt browser cache?
Any help appreciated.
thanks,
KS
Hi, ok - so I've narrowed it down a bit more. When I select an item from a drop down list control (which is a UserControl) - and then attempt to rebind my grid using the selected value, the error occurs.
The selectedvalue on postback seems to be zero every time (because the control is not in the viewstate somehow?!).
The UserControl (containing the dropdownlist) is added at design-time.
Hi, thanks for your reponse. What logic should I try moving to OnPreRender?
Another thing I missed...
-The first bind of grid works fine (on first time page load). -Selecting value from dropdownlist causes postback in which grid is bound again using values - works fine also. -When I click another button (which also triggers binding for grid), the viewstate error occurs.
Below is some code:
UserControl Source:
Imports iMWeb_BUL Imports System.Data
Partial Class TitleList Inherits System.Web.UI.UserControl
Public Event IndexHasChanged(ByVal sender As Object, ByVal e As CommandEventArgs)
Public Property TitleID() As Integer
Get
Return IIf(DDL_Titles.SelectedValue = Nothing, 0, DDL_Titles.SelectedValue)
End Get
Set(ByVal value As Integer)
Try
DDL_Titles.SelectedValue = value
Catch
End Try
End Set
End Property
Public ReadOnly Property TitleTable() As DropDownList
Get
Return DDL_Titles
End Get
End Property
Public ReadOnly Property TitleName() As String
Get
If DDL_Titles.SelectedValue > 0 Then
Return DDL_Titles.SelectedItem.ToString()
Else
Return Nothing
End If
End Get
End Property
Public Sub DDL_Titles_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDL_Titles.SelectedIndexChanged
Dim ee As CommandEventArgs = New CommandEventArgs(DDL_Titles.SelectedValue, Nothing)
RaiseEvent IndexHasChanged(Me, ee)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'bind dropdownlist
common.BindDDLs("MovieListDemo", "[SP_ListTitlesDEMO]", "MOV_ID", "movie_name", true, DDL_Titles, Nothing)
End If
End Sub
End Class
Main page logic (pseudo):
Sub Page_Load
If not postback
bindGrid()
End If
If UserControl1.IndexChanged
bindGrid()
End If
If Button1.clicked
bindGrid() <---- error occurs here
End if
Sub bingGrid
fetch data passing param TitleList1.TitleID (usercontrol)
End Sub