两个方法,一是用session全局变量,二是LoadControl("test.ascx?参数=").
注意第二种方法没有测试过

解决方案 »

  1.   

    if your UserControl have a codebehind class, do       For i As Integer = 0 To 5
                Dim dg As YourCodeBehindClass = CType(LoadControl("test.ascx"),YourCodeBehindClass)
                dg.ID = "test" + i.ToString()
                dg.Property1 = "1231"
                PlaceHolder1.Controls.Add(dg)
            Nextotherwise, use Reflection         For i As Integer = 0 To 5
                Dim dg As UserControl = CType(LoadControl("test.ascx"),UserControl)
                dg.ID = "test" + i.ToString()
                dim pi as PropertyInfo = dg.GetType().GetProperty("SomeProperty")
                pi.SetValue(dg,"123", nothing)
                PlaceHolder1.Controls.Add(dg)
            Next
    or       For i As Integer = 0 To 5
                Dim dg As UserControl = CType( LoadControl("test.ascx"), UserControl)
                dg.ID = "test" + i.ToString()
                 Dim txt as TextBox = CType(dg.FindControl("text1"), TextBox)
                  txt.Text = "123"
                PlaceHolder1.Controls.Add(dg)
            Next
      

  2.   

    dim pi as PropertyInfo = dg.GetType().GetProperty("SomeProperty")
    这一句通不过啊,我的用户控件有一个属性:cata
    我就写成了:
    dim pi as PropertyInfo = dg.GetType().GetProperty("cata")但是,提示说没有定义PropertyInfo 
    怎么改呢?谢谢!