我通过代码
创建了一些动态控件' fields is an array of string
For Each field As String In fields
If field.Trim <> "" Then
fieldqty += 1
Dim mylab As New Label
mylab.Text = field
mylab.ID = "lblInfo" & fieldqty
Dim mytxt As New TextBox
mytxt.ID = "txtInfo" & fieldqty
panInfo.Controls.Add(mylab)
panInfo.Controls.Add(mytxt)
End If
next
Session("FieldsQty") = fieldqty
然后,我有一个按钮,我想保存或通过该字段的电子邮件内容发送。
Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
For k As Integer = 1 To CInt(Session("FieldsQty"))
Dim myTxt As TextBox
Dim myLbl As Label
lblMsg.Text = panInfo.Controls.Count 'Here I got 0
myLbl = CType(panInfo.FindControl("lblInfo" & k), Label) 'HERE I get mylbl = Nothing
myTxt = CType(panInfo.FindControl("txtInfo" & k), TextBox) 'HERE I get myTxt = Nothing
next k
End Sub
似乎在我点击按钮控件后消失(不仅是它们的值:值和控件)。
我知道这些控件都是dinamically创建的,因此它们不会在回发后重新创建,但是在我点击按钮后它们就会消失,我也无法保存其中的值。为什么?
由于
编辑:好的我还有另外一个问题:如何在按钮点击时获得该控件的价值?