I am afraid it fails, with
Object reference not set to an instance of an object.
When I look at x.GetType().GetProperty("a
Thanks
Jetforce
Main Topics
Browse All TopicsHi all,
I am trying to invoke the properties of a dynamically load usercontrol. Every time I use invoke on the control I get the following message :-
Method ASP.Information_ascx.abc not found
here is the code, anybody got a solution on how to do this?
With row.Cells(0)
Dim x As Object
x = LoadControl("usercontrols\
'This works
x.abc = "kljkjkj"
'but this does not
x.GetType().InvokeMember("
.Controls.Add(x)
End With
tbl.Rows.Add(row)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This will not work, as I am building the controls dynamically, I will not know which properties/methods etc until at runtime.
The InvokeMember allows this at runtime. (Except when dealing with usercontrols it seems).
I want generic code, so if I add another usercontrol at a later date, I will not have to check all the properties for this control and this avoids a recompile.
Thanks
Jetforce
I just hate late-binding and think it should always be avoided if possible. Could you create a base class for all your usercontrols to inherit from? then just cast to that so you can early bind the properties? Any new usercontrols you add would just need to inherit from this base class. Since inheritance is an "IS-A" relationship, you can always cast to the parent class
Public Class MyBaseUserControl : Inherits System.Web.UI.UserControl
Public Property abc as string
Get
...
End Get
Set
...
End Set
End Property
End Class
Dim x As MyBaseUserControl
x = CType(LoadControl("usercon
x.abc = "blahblah"
raterus,
I think you are missing a key point, I will not know what properties are available until run-time, this will come from the XML file.
I would have to check all the XML elements and condition the settings (probably via a select case statement).
Using your suggested method, I will be late binding via polymorphisming. I do not see any difference. I may be missing something?
Thanks
Jetforce
well, I consider it early binding, but it is polymorphism. Anyway, I see what you are doing, so it won't work.
Can you give me an example of the usercontrol's class, where "abc" is defined?
Also, just a clarification, shouldn't your original statement read like this?
x.GetType().InvokeMember("
raterus,
here is the code for the control, it was being used as a test. The user control contails one label control. As for your second remark, I believe your code is exactly as my first post except for the text
Thanks
Jetforce
Public Class Information
Inherits System.Web.UI.UserControl
Private m_abc As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public Property ABC() As String
Get
Return m_abc
End Get
Set(ByVal Value As String)
m_abc = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Label1.Text = m_abc
End Sub
sorry, I'm not at a computer where I can test this, I will though. Do you think this may be a case sensitivity issue? abc vs. ABC?
x.GetType().InvokeMember("
Business Accounts
Answer for Membership
by: RuskPosted on 2005-05-18 at 08:05:23ID: 14027764
Try this instead...
bc").GetSe tMethod(). Invoke(x, New Object() {"Trial Message"})
x.GetType().GetProperty("a