dynamically generate multiView Problem

A

Avon

Hi friends,

I am very sorry for my not perfect English.

I have one question, I am using David Bauer's DynamicControlsPlaceholder to
dinamically generate controls and I am tryig to generate MultiViev, at first
it working, when I click btn1 I set SetActiveView to viev1 and it's working
OK, but when after that I click btn2 and try to set SetActiveView to 2, I
receive this error:

ActiveViewIndex is being set to '1'. It must be smaller than the current
number of View controls '0'. For dynamically added views, make sure they are
added before or in Page_PreInit event.
Parameter name: value



Please help me to understand this error



This is my code

Aspx file:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb"
Inherits="test" title="Untitled Page" %>



<%@ Register Assembly="DBauer.Web.UI.WebControls.DynamicControlsPlaceholder"
Namespace="DBauer.Web.UI.WebControls"

TagPrefix="DBWC" %>

<html >

<head id="Head1" runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="sad" runat=server>

<dbwc:dynamiccontrolsplaceholder id="DynamicControlsPlaceholder1"
runat="server"

controlswithoutids="Persist"></dbwc:dynamiccontrolsplaceholder>

<br />

<br />

<asp:Button ID="btn1" runat="server" Text="first click here" />

<asp:Button ID="btn2" runat="server" Text="then click here" />

</form>



</body>

</html>



Vb file:

Partial Class test

Inherits System.Web.UI.Page



Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

Dim m As New MultiView

DynamicControlsPlaceholder1.Controls.Add(m)

Dim i As Integer



Dim v As View

For i = 0 To 5



v = New View

m.Views.Add(v)



v.ID = "MyView" & i



Dim txt As New TextBox

v.Controls.Add(txt)



txt.ID = "txt" & i

txt.Text = "My text " & i

Next

End If

End Sub



Protected Sub btn1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btn1.Click

DirectCast(DynamicControlsPlaceholder1.Controls(0),
MultiView).SetActiveView(DirectCast(DynamicControlsPlaceholder1.Controls(0),
MultiView).Views(1))

End Sub



Protected Sub btn2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btn2.Click

DirectCast(DynamicControlsPlaceholder1.Controls(0),
MultiView).SetActiveView(DirectCast(DynamicControlsPlaceholder1.Controls(0),
MultiView).Views(2))

End Sub

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top