|
-
Apr 28th, 2006, 01:55 PM
#1
Thread Starter
Lively Member
[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?
-
Apr 28th, 2006, 02:09 PM
#2
Thread Starter
Lively Member
Re: [2005] How can I do this?
can someone move this to ASP.NET ?
-
Apr 28th, 2006, 03:27 PM
#3
Fanatic Member
Re: [2005] How can I do this?
Have you tried
oUserControl.test()
?
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
Apr 28th, 2006, 03:33 PM
#4
Re: [2005] How can I do this?
 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();
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Apr 28th, 2006, 03:37 PM
#5
Frenzied Member
Re: [2005] How can I do this?
Is the CTYpe messing you up? I would use:
DirectCast(oUserControl, TestControl).Test()
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
May 1st, 2006, 10:59 AM
#6
Thread Starter
Lively Member
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
-
May 1st, 2006, 11:02 AM
#7
Thread Starter
Lively Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|