Hi all, I have changed my code very samller than before and used arrays to fill tabs instead of DB data. You can remove the cssClass and stylesheet from the html page in order to work for you. Hope that helps you to help me:)
Note: I know the code is long but if you copy the code into your visual studio and run it, you can see what I experience here. Problem is in the InsertRowsToTables function where textboxes are xreated for the first time but do not appear after the first tab visit..
It started with creating a tab control in VB.net and I got some ideas online and changed them to my own version. Everything was fine except when I was going to a tab for the second time (or anytime after the first visit to that tab), the changes I made to its content (textboxes) did not exist. I found that the page is loading everytime I visit a tab and data would be refreshed from DB. So I changed my tab deisgn from Mutilview to Panels first. Then I did not load all data into my tabs on page load. The first tab was loaded from database on page load and when user was clicking a new tab, then its data was being loaded to that tab. I used a session variable this time to keep trak of number of visits to that tab stop loading data more than one time. So if it was more than once, I stopped loading data from DB. Well, it worked partially and changes to each textbox was there after I visited each tab several times.
Problem:
In some of tabs, I use a function to loop thru several records and show them, like several Contact information for each person will be listed in group of data under that tab. The first contact textboxes is already in a <asp:table> in my page and if there is no contact info in DB, I just show the empty boxes along with their labels. But other records are created dynamically using TableRows and TableCells that are added to the existing <asp:table> in my page. Now, I can not see more than one record for the Contact tab and the rest of information disappears! Anyone knows how to slove this? Thanks in advance.
Here are some codes that might help you:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test File</title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu ID="TabMenu" runat="server" cssClass="TabClass" orientation="Horizontal" StaticEnableDefaultPopOutimage="false" OnMenuItemClick="TabMenu_MenuItemClick" Visible="false" ViewStateMode="Inherit">
<Items>
<asp:MenuItem text=" " Value="0"> </asp:MenuItem>
<asp:MenuItem text=" " Value="1"></asp:MenuItem>
</Items>
</asp:Menu>
<asp:Panel id="Panel1" runat="server" Visible="False">
<table>
<tr valign="top">
<td id="GItd" class="TabArea" >
<table id="GenInfotbl" runat="server" cellspacing="10" >
<tr id="Tr2" runat="server" >
<td>
<asp:Label ID="FNamelbl" cssClass="bold" runat="server" Text="First Name:" Width="200"></asp:Label>
</td>
<td><asp:TextBox ID="FNametxtbox" runat="server" Width="200"></asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel id="Panel2" runat="server" Visible="False">
<table>
<tr valign="top">
<td id="Ctd" class="TabArea" >
<asp:Table ID="CtblASP" runat="server" cellspacing="10">
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="CLNamelbl1" cssClass="bold" runat="server" Text="Last Name:" Width="200"></asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="CLNametxtbox1" runat="server" Width="200"></asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="CHPhonelbl1" cssClass="bold" runat="server" Text="Home Phone:" Width="150"></asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="CHPhonetxtbox1" runat="server" Width="200"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>
and in code section, I have :
Public Class testTab
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TabMenu.Items(0).Text = "" & "General Information |" & ""
TabMenu.Items(1).Text = " Contact"
Dim QStr
QStr = 3
Fillpanel1(QStr)
FNametxtbox.Focus()
Panel1.Visible = True
End Sub
Protected Function Fillpanel1(QStr As Integer)
Dim i
TabMenu.Visible = True
If Not IsPostBack Then
Dim myarr(2, 1)
myarr(0, 0) = "1"
myarr(0, 1) = "Larry"
myarr(1, 0) = "2"
myarr(1, 1) = "Mike"
myarr(2, 0) = "3"
myarr(2, 1) = "Tim"
For i = 0 To UBound(myarr)
If myarr(i, 0) = QStr Then
FNametxtbox.Text = myarr(i, 1)
End If
Next
End If
Return True
End Function
Protected Sub TabMenu_MenuItemClick(ByVal sender As Object, _
ByVal e As MenuEventArgs) Handles TabMenu.MenuItemClick
Dim QStr = 3
Panel1.Visible = False
Panel2.Visible = False
Select Case Int32.Parse(e.Item.Value)
Case 0
Panel1.Visible = True
Session("Panel1") = Session("Panel1") + 1
Fillpanel1(QStr)
Case 1
Session("Panel2") = Session("Panel2") + 1
Panel2.Visible = True
Fillpanel2()
End Select
End Sub
Protected Function Fillpanel2()
If Session("Panel2") < 2 Then
Dim cellCnt
Dim cellCtr
Dim lastCellItem
Dim TabTableName As Table
cellCnt = 2
cellCtr = 1
lastCellItem = "Home Phone:"
TabTableName = CtblASP
Dim myarrContact(3, 1) As String
myarrContact(0, 0) = "Wilson"
myarrContact(0, 1) = "1-222-333-4444"
myarrContact(1, 0) = "Miller"
myarrContact(1, 1) = "1-333-444-5555"
myarrContact(2, 0) = "Shoemaker"
myarrContact(2, 1) = "1-444-555-6666"
For i = 0 To 3
If i > 0 Then
If i = 3 Then
Exit For
End If
InsertRowsToTables(TabTableName, i, cellCtr, cellCnt, myarrContact)
Else
CLNametxtbox1.Text = myarrContact(0, 0)
CHPhonetxtbox1.Text = myarrContact(0, 1)
End If
Next
End If
Return True
End Function
Protected Function InsertRowsToTables(TabTableNameF As Table, iFun As Integer, cellCtrF As Integer, cellCntF As Integer, myarrContact As Array)
Dim j As Integer
For cellCtrF = 1 To cellCntF
Dim tRow As New TableRow()
j = cellCtrF - 1
Dim tCell As New TableCell()
Select Case j
Case 0
tCell.Text = "Last name:"
Case 1
tCell.Text = "Home Phone:"
End Select
Select Case j
Case 0
tCell.ID = "CLNamelbl" & iFun + 1
Case 1
tCell.ID = "CHPhonelbl" & iFun + 1
End Select
tCell.Width = 150
tRow.Cells.Add(tCell)
Dim tCellTxt As New TableCell()
Dim tb As TextBox = New TextBox
If Len(Convert.ToString(myarrContact(iFun, j))) = 0 Then
tb.Text = ""
Else
tb.Text = myarrContact(iFun, j)
End If
tb.Width = 200
tCellTxt.Width = 200
tCellTxt.Controls.Add(tb)
Select Case j
Case 0
tb.ID = "CLNametxtbox" & iFun + 1
Case 1
tb.ID = "CHPhonetxtbox" & iFun + 1
End Select
tRow.Cells.Add(tCellTxt)
If cellCtrF Mod 2 = 0 Then
Dim tRowNL As New TableRow()
Dim tCellNL As New TableCell()
tCellNL.Text = ""
tRowNL.Cells.Add(tCellNL)
TabTableNameF.Rows.Add(tRowNL)
ElseIf cellCtrF = cellCntF Then
TabTableNameF.Rows.Add(tRow)
Else
cellCtrF = cellCtrF + 1
If cellCtrF <= cellCntF Then
j = cellCtrF - 1
Dim tCell2 As New TableCell()
Select Case j
Case 0
tCell2.Text = "Last name:"
Case 1
tCell2.Text = "Home Phone:"
End Select
Select Case j
Case 0
tCell2.ID = "CLNamelbl" & iFun + 1
Case 1
tCell2.ID = "CHPhonelbl" & iFun + 1
End Select
tCell2.Width = 150
tRow.Cells.Add(tCell2)
Dim tCellTxt2 As New TableCell()
Dim tb2 As TextBox = New TextBox
tb2.Width = 200
If Len(Convert.ToString(myarrContact(iFun, j))) = 0 Then
tb2.Text = ""
Else
tb2.Text = myarrContact(iFun, j)
End If
tCellTxt2.Width = 200
tCellTxt2.Controls.Add(tb2)
Select Case j
Case 0
tb.ID = "CLNametxtbox" & iFun + 1
Case 1
tb.ID = "CHPhonetxtbox" & iFun + 1
End Select
tRow.Cells.Add(tCellTxt2)
TabTableNameF.Rows.Add(tRow)
End If
End If
Next
Return True
End Function
End Class