动态控件取值问题。急!
在页面中点击一个按钮,动态创建一些控件,然后我需要点击保存按钮进行保存,但是当我点击保存按钮后,整个页面就刷新了,动态控件已经消失,那样控件中的值无法取到?????我该怎样做??用Session?或者ViewState?高手有好方法吗????着急啊,各位帮忙吧~~~
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim lab As New Label
PlaceHolder1.Controls.Add(lab)
lab.ID = "lab1"
lab.Text = "标签文本"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mylab As Label
mylab = PlaceHolder1.FindControl("lab1")
Dim mystr As String
mystr = mylab.Text
Response.Write(mystr)
End Sub
为什么它就运行错误呢。可以把控件添加到页面。但是为什么在点击按钮取控件值的时候就运行错误了呢,