Rank: Member Groups: Member
Joined: 12/5/2007 Posts: 27
|
Hello, I've been researching for HOURS why suddenly my eo.datepicker wasn't preserving its state !! It turned out that I just introduced a new code in the LoadCompleted event on the page that adds a control to the form. doing that, the datepicker loses all track of ViewState while the other ASP controls work perfectly ... hard to find ... so far I've just tested it and prove it to NOT work on DatePicker. this is the code I use in the LoadComplete event for the page;
Code: Visual Basic.NET
' Get the div from the page if it exists
Me.msgDiv = Me.FindControl("MessageHeader")
' if it doesn't, attempt to add a new div disabled since EO gives problems
If msgDiv Is Nothing Then
msgDiv = New html.HtmlGenericControl("div")
msgDiv.ID = "MessageHeader"
Try
Me.Form.Controls.AddAt(0, msgDiv)
Catch ex As Exception
Try
Me.Form.Controls.Add(msgDiv)
Catch ex2 As Exception
Exit Sub
End Try
End Try
End If
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi,
We looked into the issue. The problem is caused by the way the state information is loaded. The information is loaded by index, not by name. So when you insert a new control as the first child in the form, this new control actually gets the original first control's state data, and the state data for the DatePicker control is also shifted to somebody else. The easiest way to fix this problem is to place a static PlaceHolder control in your form, and then add your dynamic control as child control of that PlaceHolder control. That way it only affects state information inside that branch, not anybody else.
Thanks
|
Rank: Member Groups: Member
Joined: 12/5/2007 Posts: 27
|
mmmm, yeah, actually, that's useful for a control that will be going to a specific page, but this control is actually in every page and re-usability and maintenance issues prevent me from adding a place holder in every single page ...
Any other control in ASP.NET seems to keep the View State fine, even if its index is after the new inserted index ... but ...
Thanks anyway for the research ;)
|