Home All Groups Group Topic Archive Search About
Author
21 Feb 2006 6:34 PM
Shawn
I have a webpage that uses a drop down box of numbers to dynamically
generate a number of textboxes that are added to a panel control. It works
fine until a postback. Then they all dissappear. I have set the
EnableViewState to true, but it still happens. Any ideas?

Protected Sub btnNumInGroup_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnNumInGroup.Click

Dim vbCount As Integer = CInt(ddlNumOfPeople.text)

Dim i As Integer

For i = 1 To vbCount

Dim vbNewTextBox As New TextBox

vbNewTextBox.MaxLength = 100

vbNewTextBox.Width = 200

vbNewTextBox.ID = "txtPeople" & i

vbNewTextBox.EnableViewState = True

pnlNames.Controls.Add(vbNewTextBox)

Next

lblEnterNames.Visible = True

End Sub

Author
21 Feb 2006 8:15 PM
blackstaronline.net
What does your Page_Load Sub look like? If in your Page_Load you are
clearing your page of any custom controls that code will run on a
postback. If you are, I would suggest putting that code in 'If Not
IsPostBack'

Can you show more code in the Page_Load section?

Jeremy Reid
http://hgtit.com
Author
22 Feb 2006 12:00 AM
Shawn
Here is what I have, neither one of the sub calls have anything to do with
the custom controls.

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

cnn = New SqlClient.SqlConnection(Application("DatabaseSettings"))

If Not IsPostBack = True Then

GetComp()

GetHistory()

End If

End Sub

Sub GetComp()

lbComp.Items.Clear()

cmd = cnn.CreateCommand

cnn.Open()

cmd.CommandText = "Select Replace(CompName, '_', '') from Companies where
active = 1 and not CompName = 'CCCI' order by CompName"

cmd.CommandType = System.Data.CommandType.Text

Dim CompReader As SqlClient.SqlDataReader

CompReader = cmd.ExecuteReader

While CompReader.Read

lbComp.Items.Add(CompReader.Item(0))

End While

CompReader.Close()

cnn.Close()

End Sub

Sub GetHistory()

cnn = New SqlClient.SqlConnection(Application("DatabaseSettings"))

cmd = cnn.CreateCommand

cnn.Open()

cmd = cnn.CreateCommand

cmd.CommandText = "select GroupID, Name + ' - ' + (Select Replace(CompName,
'_', '') from Companies where " & _

"CompID = a.CompID) as Name from Groups a where RegisteredBy = @UserName
order by name"

cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 100).Value =
Session("Username")

cmd.CommandType = System.Data.CommandType.Text

da.SelectCommand = cmd

da.Fill(ds, "Groups")

ViewState("SelectedGroup") = ds

If ds.Tables(0).Rows.Count = 0 Then

lbHistory.Enabled = False

lbHistory.Items.Add("No groups pre-registered")

cmd.Parameters.Clear()

cnn.Close()

da.Dispose()

Exit Sub

End If

Dim Reader As System.Data.SqlClient.SqlDataReader

Reader = cmd.ExecuteReader

While Reader.Read = True

lbHistory.Items.Add(Reader.GetString(1))

End While

Reader.Close()

cmd.Parameters.Clear()

cnn.Close()

da.Dispose()

End Sub

Show quoteHide quote
"blackstaronline.net" <jr***@blackstaronline.net> wrote in message
news:1140552954.481208.159160@o13g2000cwo.googlegroups.com...
> What does your Page_Load Sub look like? If in your Page_Load you are
> clearing your page of any custom controls that code will run on a
> postback. If you are, I would suggest putting that code in 'If Not
> IsPostBack'
>
> Can you show more code in the Page_Load section?
>
> Jeremy Reid
> http://hgtit.com
>
Author
22 Feb 2006 12:19 AM
Shawn
Nevermind, I got it.. So easy it made me feel dumb actually. Here is the
article I found...

http://www.codeproject.com/aspnet/retainingstate.asp

Show quoteHide quote
"Shawn" <shawn.cam***@ccci.org> wrote in message
news:uOOb6L0NGHA.3908@TK2MSFTNGP10.phx.gbl...
> Here is what I have, neither one of the sub calls have anything to do with
> the custom controls.
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
>
> cnn = New SqlClient.SqlConnection(Application("DatabaseSettings"))
>
> If Not IsPostBack = True Then
>
> GetComp()
>
> GetHistory()
>
> End If
>
> End Sub
>
> Sub GetComp()
>
> lbComp.Items.Clear()
>
> cmd = cnn.CreateCommand
>
> cnn.Open()
>
> cmd.CommandText = "Select Replace(CompName, '_', '') from Companies where
> active = 1 and not CompName = 'CCCI' order by CompName"
>
> cmd.CommandType = System.Data.CommandType.Text
>
> Dim CompReader As SqlClient.SqlDataReader
>
> CompReader = cmd.ExecuteReader
>
> While CompReader.Read
>
> lbComp.Items.Add(CompReader.Item(0))
>
> End While
>
> CompReader.Close()
>
> cnn.Close()
>
> End Sub
>
> Sub GetHistory()
>
> cnn = New SqlClient.SqlConnection(Application("DatabaseSettings"))
>
> cmd = cnn.CreateCommand
>
> cnn.Open()
>
> cmd = cnn.CreateCommand
>
> cmd.CommandText = "select GroupID, Name + ' - ' + (Select
> Replace(CompName, '_', '') from Companies where " & _
>
> "CompID = a.CompID) as Name from Groups a where RegisteredBy = @UserName
> order by name"
>
> cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 100).Value =
> Session("Username")
>
> cmd.CommandType = System.Data.CommandType.Text
>
> da.SelectCommand = cmd
>
> da.Fill(ds, "Groups")
>
> ViewState("SelectedGroup") = ds
>
> If ds.Tables(0).Rows.Count = 0 Then
>
> lbHistory.Enabled = False
>
> lbHistory.Items.Add("No groups pre-registered")
>
> cmd.Parameters.Clear()
>
> cnn.Close()
>
> da.Dispose()
>
> Exit Sub
>
> End If
>
> Dim Reader As System.Data.SqlClient.SqlDataReader
>
> Reader = cmd.ExecuteReader
>
> While Reader.Read = True
>
> lbHistory.Items.Add(Reader.GetString(1))
>
> End While
>
> Reader.Close()
>
> cmd.Parameters.Clear()
>
> cnn.Close()
>
> da.Dispose()
>
> End Sub
>
> "blackstaronline.net" <jr***@blackstaronline.net> wrote in message
> news:1140552954.481208.159160@o13g2000cwo.googlegroups.com...
>> What does your Page_Load Sub look like? If in your Page_Load you are
>> clearing your page of any custom controls that code will run on a
>> postback. If you are, I would suggest putting that code in 'If Not
>> IsPostBack'
>>
>> Can you show more code in the Page_Load section?
>>
>> Jeremy Reid
>> http://hgtit.com
>>
>
>