C# 以编程方式实例化asp.net页面及其控件

C# 以编程方式实例化asp.net页面及其控件,c#,asp.net,.net,vb.net,automation,C#,Asp.net,.net,Vb.net,Automation,我有一个asp.net页面,其中的方法使用页面上的控件。我需要实例化这个页面,自动化一些用户交互,选择单选按钮,点击按钮等等 在大多数情况下,这是可行的,但我必须以编程方式实际实例化我想要使用的每个控件。是否有一种方法/技术可以实例化所有控件,就像页面在发送到浏览器之前加载时所做的那样 Dim myTempForm As New form1 mytempForm.label1 = "demo text" <--- label1 is Nothing --- object referenc

我有一个asp.net页面,其中的方法使用页面上的控件。我需要实例化这个页面,自动化一些用户交互,选择单选按钮,点击按钮等等

在大多数情况下,这是可行的,但我必须以编程方式实际实例化我想要使用的每个控件。是否有一种方法/技术可以实例化所有控件,就像页面在发送到浏览器之前加载时所做的那样

Dim myTempForm As New form1

mytempForm.label1 = "demo text" <--- label1 is Nothing --- object reference not set

mytempForm.label1 = new Label 

myTempForm.label1 = "demo text" <-- now works as expected, I can use it...

最后在原始问题中使用了我的代码块

For Each Control In Me.Controls

    If TypeOf (Control) Is Label Then
        Control = New Label
    ElseIf TypeOf (Control) Is Panel Then
        Control = New Panel
    ElseIf TypeOf (Control) Is TextBox Then
        Control = New TextBox
    ElseIf TypeOf (Control) Is RadioButton Then
        Control = New RadioButton
    ElseIf TypeOf (Control) Is Button Then
        Control = New Button
    ElseIf TypeOf (Control) Is UpdatePanel Then
        Control = New UpdatePanel
    End If

Next