Dynamic tabstrip and multipage

E

Elad Frid

Hi

I'm creating an asp net application with dynamic controls,
I have a dynamic tabstrip and multipage and each page is filed with
several controls types based on SQl database.( The code that create
them in in the Page_Init )
The problem - When I first load the page everything works OK and when
the page is post back all other controls are created again as I want
but
I get duplicated tabs that are not connected to any page.

While drPage.Read()
' Add new TAB to TabStrip
NewTab = New Microsoft.Web.UI.WebControls.Tab()
NewTab.Text = drPage("SectionName")
tsKR.Items.Add(NewTab)
' Add new Separator to TabStrip
NewSeparator = New
Microsoft.Web.UI.WebControls.TabSeparator()
tsKR.Items.Add(NewSeparator)
' Add new Page to MultiPage
NewPageView = New Microsoft.Web.UI.WebControls.PageView()
mpKR.Controls.Add(NewPageView)
' Add panel to page
Dim Panel = New Panel()
Panel.ID = "Panel" & drPage("SectionName")
Panel.Style("Top") = "100px"
Panel.Style("Hight") = "1000px"
NewPageView.Controls.Add(Panel)

Create controls....
End While


Elad.
 
S

Scott

I think the Tab controls are tracked in ViewState; add a if (!IsPostBack) around the tab creation and it should keep them from duplicating.

Scott

Hi

I'm creating an asp net application with dynamic controls,
I have a dynamic tabstrip and multipage and each page is filed with
several controls types based on SQl database.( The code that create
them in in the Page_Init )
The problem - When I first load the page everything works OK and when
the page is post back all other controls are created again as I want
but
I get duplicated tabs that are not connected to any page.

While drPage.Read()
' Add new TAB to TabStrip
NewTab = New Microsoft.Web.UI.WebControls.Tab()
NewTab.Text = drPage("SectionName")
tsKR.Items.Add(NewTab)
' Add new Separator to TabStrip
NewSeparator = New
Microsoft.Web.UI.WebControls.TabSeparator()
tsKR.Items.Add(NewSeparator)
' Add new Page to MultiPage
NewPageView = New Microsoft.Web.UI.WebControls.PageView()
mpKR.Controls.Add(NewPageView)
' Add panel to page
Dim Panel = New Panel()
Panel.ID = "Panel" & drPage("SectionName")
Panel.Style("Top") = "100px"
Panel.Style("Hight") = "1000px"
NewPageView.Controls.Add(Panel)

Create controls....
End While


Elad.
 
E

Elad Frid

Hi

You are right but I'm creating dynamic controls on each multi page
and if I add the "If Not Page.IsPostBack Then" line I will not be able
to find and access the dynamic controls I have created on the multi
page

Here is a new code example:

Private Sub Demo1()
Dim NewTab As Microsoft.Web.UI.WebControls.Tab
Dim NewSeparator As Microsoft.Web.UI.WebControls.TabSeparator

' If Not Page.IsPostBack Then
' Create Tabs
NewTab = New Microsoft.Web.UI.WebControls.Tab()
NewTab.Text = "new tab1"
tsKR.Items.Add(NewTab)

NewSeparator = New
Microsoft.Web.UI.WebControls.TabSeparator()
tsKR.Items.Add(NewSeparator)

NewTab = New Microsoft.Web.UI.WebControls.Tab()
NewTab.Text = "new tab2"
tsKR.Items.Add(NewTab)

' Create pages view
Dim NewPageView1 As New PageView()
NewPageView1.ID = "PageView1"
mpKR.Controls.Add(NewPageView1)

Dim NewPageView2 As New PageView()
NewPageView2.ID = "PageView2"
mpKR.Controls.Add(NewPageView2)
' End If

Dim TextBox9 As New TextBox()
TextBox9.ID = "9"
TextBox9.Style("Top") = "60px"
TextBox9.Style("Left") = "100px"
FindControl("PageView1").Controls.Add(TextBox9)

Dim dropdownlist1 As New DropDownList()
dropdownlist1.ID = "6"
dropdownlist1.Style("Top") = "60px"
dropdownlist1.Style("Left") = "100px"
dropdownlist1.Items.Add("1")
dropdownlist1.Items.Add("2")
dropdownlist1.AutoPostBack = True
FindControl("PageView2").Controls.Add(dropdownlist1)
End Sub

Elad.
 
S

Scott G.

The tab strip keeps track of the tabs in ViewState (via the Items collection I guess); the PageView controls do not; so you either have to split your code in two (add the the tabs when !IsPostback and then add the PageViews each time); or you have to turn off the ViewState for the TabStrip (and if that can't be done then clear the tab strip each time -- you'll probably have to keep track of the active tab when doing things this way).

The way I do this is kinda like this:

protected override void CreateChildControls()
{
FormTabs = new TabStrip();
if (!IsPostBack)
{
foreach (tab-want-to-create)
{
Tab t = new Tab();
FormTabs.Items.Add(t);
}
}

FormPages = new MultiPage();
foreach (page--want-to-create)
{
FormPage.Controls.Add(new PageView());
}
Controls.Add(FormPages);
FormTabs.TargetId = ID of FormPages;
Controls.Add(FormTabs);
}

Scott
Hi

You are right but I'm creating dynamic controls on each multi page
and if I add the "If Not Page.IsPostBack Then" line I will not be able
to find and access the dynamic controls I have created on the multi
page

Here is a new code example:

Private Sub Demo1()
Dim NewTab As Microsoft.Web.UI.WebControls.Tab
Dim NewSeparator As Microsoft.Web.UI.WebControls.TabSeparator

' If Not Page.IsPostBack Then
' Create Tabs
NewTab = New Microsoft.Web.UI.WebControls.Tab()
NewTab.Text = "new tab1"
tsKR.Items.Add(NewTab)

NewSeparator = New
Microsoft.Web.UI.WebControls.TabSeparator()
tsKR.Items.Add(NewSeparator)

NewTab = New Microsoft.Web.UI.WebControls.Tab()
NewTab.Text = "new tab2"
tsKR.Items.Add(NewTab)

' Create pages view
Dim NewPageView1 As New PageView()
NewPageView1.ID = "PageView1"
mpKR.Controls.Add(NewPageView1)

Dim NewPageView2 As New PageView()
NewPageView2.ID = "PageView2"
mpKR.Controls.Add(NewPageView2)
' End If

Dim TextBox9 As New TextBox()
TextBox9.ID = "9"
TextBox9.Style("Top") = "60px"
TextBox9.Style("Left") = "100px"
FindControl("PageView1").Controls.Add(TextBox9)

Dim dropdownlist1 As New DropDownList()
dropdownlist1.ID = "6"
dropdownlist1.Style("Top") = "60px"
dropdownlist1.Style("Left") = "100px"
dropdownlist1.Items.Add("1")
dropdownlist1.Items.Add("2")
dropdownlist1.AutoPostBack = True
FindControl("PageView2").Controls.Add(dropdownlist1)
End Sub

Elad.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top