I'm looking to create identical sets of controls right under each other after the user clicks a button. What I have here is replacing the same set of controls over and over again. Any help would be appreciated it!
Imports System.Data.SqlClient
Imports System.Data
Imports System.Net.Mail
Imports System.Web.UI.Page
Imports System.Web.UI.WebControls
Partial Class _Default
Inherits System.Web.UI.Page
Function intWriterCount() As Integer
Try
Return Convert.ToInt32(ViewState("WriterCount"))
Catch
Return 0
End Try
ViewState("WriterCount") = value
End Function
Sub LoadViewState()
If ViewState("controlsadded1") Then
Dim arrCounts() As String = strSavedCount.Split(",")
For Each s As String In arrCounts
AddNewWriterRow(Convert.ToInt32(s.Trim()))
Next
End If
End Sub
Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad
If Not IsPostBack Then
intWriterCount = 0
AddCount(0)
AddNewWriterRow(0)
intWriterCount += 1
End If
End Sub
Function strSavedCount() As String
If (ViewState("SavedCounts") = "") Then
Return ""
Else
Return (ViewState("SavedCounts")).ToString()
End If
End Function
Sub AddCount(ByVal i As Integer)
If ViewState("SavedCounts") = "" Then
ViewState("SavedCounts") = i.ToString
Else
ViewState("SavedCounts") = ViewState("SavedCounts").ToString + "," + i.ToString
End If
End Sub
Sub AddNewWriterRow(ByVal intCounter As Integer)
Dim txtWriter As New TextBox
Dim txtPercentage = New TextBox
txtWriter.ID = "txtWriter" + intCounter
txtWriter.CssClass = "medium"
txtWriter.Width = 120
txtPercentage.ID = "txtPercentage" + intCounter
txtPercentage.CssClass = "medium"
txtPercentage.Width = 50
pnlWriters.Controls.Add(New LiteralControl("<tr><td>"))
pnlWriters.Controls.Add(txtWriter)
pnlWriters.Controls.Add(New LiteralControl("</td><td>"))
pnlWriters.Controls.Add(txtPercentage)
pnlWriters.Controls.Add(New LiteralControl("</td><td>"))
ViewState("controlsadded2") = True
End Sub
Sub btnAddRow_Click()
Dim arrCounts() As String = strSavedCount.Split(",")
If (arrCounts.Length > 20) Then
Throw New Exception("Only 20 allowed")
Else
AddNewWriterRow(intWriterCount)
AddCount(intWriterCount)
intWriterCount += 1
End If
End Sub
End Class
I'm having trouble with "value" and "intWriterCount"