VB.net/Asp.net使用要设置的公共属性以编程方式加载控件

时间:2011-10-12 14:34:16

标签: asp.net vb.net controls

我有一个vb.net asp应用程序,我正在加载一个控件(来自页面上的另一个控件)。我想在加载时在两个控件之间设置一个变量。

这是我加载控件的地方:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim AuditControl As Control = LoadControl("~/controls/auditcompanies.ascx")
        phCompanies.Controls.Add(AuditControl)
    End Sub

在正在加载的控件上,我公开了我想要更改为属性的项目

Public Property resultType() As String
        Get
            Return m_resultType
        End Get
        Set(ByVal value As String)
            m_resultType = value
        End Set
    End Property

基本上它所做的就是为我的表适配器

设置一个参数
 Public Sub Load_Data()

        dtblog = New dsDECorp.ClientInfoDataTable
        dtblog = tablog.GetAudits(m_resultType)
        For Each rClient As dsDECorp.ClientInfoRow In dtblog

            CID = rClient.ClientID
            ClientName = rClient.CompanyName

        Next
        dtblog.Dispose()
    End Sub

如何在加载时将参数从第一个控件传递到第二个控件?

由于

汤姆

1 个答案:

答案 0 :(得分:0)

我是C#的家伙,请原谅我,如果我犯了任何语法错误,但以下内容对您有用:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     Dim AuditControl As Control = LoadControl("~/controls/auditcompanies.ascx")
     Dim AuditControlType As Type = AuditControl.GetType()
     Dim AuditField As FieldInfo = AuditControlType.GetField("resultType")
     AuditField.SetValue(AuditControlType, "Your Value")
     phCompanies.Controls.Add(AuditControl)
 End Sub