[2005] How can I do this?
Say I have a custom control - TestControl.ascx
if I had code like this on a page
Code:
dim oUserControl as UserControl
oUserControl = LoadControl("TestControl.ascx")
pnlMain.controls.add(oUserControl)
Say TestControl has a public method called test.. I want to be able to go
Code:
CType(oUserControl, TestControl).Test()
however, it doesn't seem like it'll work... any input?
Re: [2005] How can I do this?
can someone move this to ASP.NET ?
Re: [2005] How can I do this?
Have you tried
oUserControl.test()
?
Re: [2005] How can I do this?
Quote:
Originally Posted by BootsSiR
however, it doesn't seem like it'll work... any input?
Have you actually tried it? It seems like you are conjecturing, and from experience, it should work.
Now, I work in the C# world, not the VB World, but the following works fine:
UserControlType oUC = new UserControlType();
this.Controls.Add(oUC);
[...]
UserControl oControl = Page.FindControl("oUCIdentifier");
(oUC)(oControl).Test();
Re: [2005] How can I do this?
Is the CTYpe messing you up? I would use:
DirectCast(oUserControl, TestControl).Test()
Re: [2005] How can I do this?
My web user control is delared as follows
Code:
Partial Class Controls_TestControl
Dim m_SzTest as String
Public Sub Test()
m_szTest = "hello"
End Sub
End Class
this code
Code:
dim oUserControl as UserControl
oUserControl = LoadControl("TestControl.ascx")
DirectCast(oUserControl, Controls_TestControl).Test()
pnlMain.controls.add(oUserControl)
gives me the error Type 'Controls_TestControl' is not defined
Re: [2005] How can I do this?
I can't even
Code:
Dim oUserControl as Controls_TestControl = LoadControl("TestControl.ascx")
do I have to add a reference to the control?