源代码:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   If Not Page.IsPostBack Then
      Dim tRow As New TableRow()
      Dim tCell As New TableCell()
      Dim TextBox1 As New TextBox()
      tCell = New TableCell()
      TextBox1 = New TextBox()
      TextBox1.ID = "WellName"
      TextBox1.Width = 100
      TextBox1.Text = "WellName"
      tCell.Controls.Add(TextBox1)
      tRow.Cells.Add(tCell)
      BedData.Rows.Add(tRow)
   Else
      Dim MyControl As Control = BedData.FindControl("WellName")
      If (Not MyControl Is Nothing) Then
          Dim WellName As String = MyControl.ToString
      Else
          Response.Write("没找到")
      End If
   End If
End Sub
其中:BedData为Table控件

解决方案 »

  1.   

    用Page.FindControl("WellName")来查找吧
      

  2.   

    在page_load事件动态创建控件的话都不要放在Not IsPostBack里面!!!!!!!
      

  3.   

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          Dim tRow As New TableRow()
          Dim tCell As New TableCell()
          Dim TextBox1 As New TextBox()
          tCell = New TableCell()
          TextBox1 = New TextBox()
          TextBox1.ID = "WellName"
          TextBox1.Width = 100
          TextBox1.Text = "WellName"
          tCell.Controls.Add(TextBox1)
          tRow.Cells.Add(tCell)
          BedData.Rows.Add(tRow)
       
          Dim MyControl As Control = BedData.FindControl("WellName")
          If (Not MyControl Is Nothing) Then
              Dim WellName As String = MyControl.ToString
          Else
              Response.Write("没找到")
          End If
       End Sub
      

  4.   

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          Dim tRow As New TableRow()
          Dim tCell As New TableCell()
          Dim TextBox1 As New TextBox()
          tCell = New TableCell()
          TextBox1 = New TextBox()
          TextBox1.ID = "WellName"
          TextBox1.Width = 100
          TextBox1.Text = "WellName"
          tCell.Controls.Add(TextBox1)
          tRow.Cells.Add(tCell)
          BedData.Rows.Add(tRow)
       
          Dim MyText As TextBox = CType(BedData.FindControl("WellName"), TextBox)
          If (Not MyText Is Nothing) Then
              Response.Write(MyText.Text)'这里取到的是默认值,和用户输入文本框的数据不一致,因为这时VIEWSTATE还没把值赋给文本框
          Else
              Response.Write("没找到")
          End If
       End Sub
      

  5.   

    真搞不懂为什么取值你得放在page_load里面,而不是放在其他比如按钮点击事件么?
      

  6.   

    在page_load事件动态创建控件的话都不要放在Not IsPostBack里面动态创建的需要每次都创建,不然NOT IsPostBack的时候没有创建控件,当然就找不到了