[ASP.NET 2.0] Dynamic MultiView! HELP!

Associate
Joined
6 Jun 2004
Posts
2,389
Location
London
This problem is driving me crazy, I'm using ASP.NET 2.0 and I've got a PlaceHolder which, in my Page_Load event, I am populating with 1 control, a MultiView.

I generate & add 1 or more views into this multiview before adding it to the placeholder, this is also done within Page_Load:

Code:
Dim j As Integer = 0
Dim ImageMultiView As MultiView = New MultiView()
ImageMultiView.ID = "ImageMultiView"


If Not Session("UploadQueue") Is Nothing Then
 For Each image As WEBayImage In CType(Session("UploadQueue"), List(Of WEBayImage))

  Dim viewPlaceHolder As View = New View()
  viewPlaceHolder.EnableViewState = False
  viewPlaceHolder.ID = image.name.Remove(image.name.LastIndexOf("."), 4) & "_" & j

  Dim imagePlaceHolder As Image = New Image()
  imagePlaceHolder.ImageUrl = "ShowImage.aspx?ImageID=" & j

  viewPlaceHolder.Controls.Add(imagePlaceHolder)

  ImageMultiView.Views.Add(viewPlaceHolder)

  j += 1
 Next
End If
PlaceHolder1.Controls.AddAt(0, ImageMultiView)

The problem lies when I get to the last line, at this point the MultiView's ActiveViewIndex gets set back to what it was on the previous page.
I proved this by outputing ImageMultiView.ActiveViewIndex before and after I add it to the PlaceHolder1 and sure enough, it gets updated to it's value I was using when I last saw the page.
Ofcourse, this gives me an error when the page_load event I am firing is as a result of me deleting an item from the Session("UploadQueue") list (so now there is one less View, therefore the ActiveViewIndex could be out of range):

"ActiveViewIndex is being set to '2'. It must be smaller than the current number of View controls '2'."

How can I stop this from happening? I've tried setting all the element's EnableViewState to False but the problem still remains...
 
Back
Top Bottom