[英]VB.net/Asp.net loading a control programatically with a public property to be set
I have a vb.net asp application where I'm loading a control (from another control on a page). 我有一个vb.net asp应用程序,正在其中加载控件(从页面上的另一个控件)。 I want to set a variable between the two controls when it loads.
我想在加载时在两个控件之间设置一个变量。
This is where I load the control: 这是我加载控件的地方:
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
On the control that's being loaded i've exposed the item i want to change as a property 在正在加载的控件上,我已经公开了要更改的属性
Public Property resultType() As String
Get
Return m_resultType
End Get
Set(ByVal value As String)
m_resultType = value
End Set
End Property
Basically all it is doing is setting a parameter for my table adaptor 基本上它所做的就是为我的表适配器设置一个参数
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
How do I pass the parameter through the property from the first control to the second when it loads? 如何在加载时将参数从第一个控件传递到第二个控件?
Thanks 谢谢
Tom 汤姆
I'm a C# guy so forgive me if I make any syntax errors but the following should work for you: 我是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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.