Starr Duskk
asked on
Calling a function of a dynamically loaded usercontrol
I am loading a user control:
userControlName = "~/Modules/Login/Controls/ RegisterCo ntrol.ascx "
Dim userControl As Control = Page.LoadControl(userContr olName)
userControl.ID = "pvRegister" & e.PageView.ID
e.PageView.Controls.Add(us erControl)
Now I want to call a function of that user control to set some values within it. How do I call a dynamically created control?
I know I could do it with this if it weren't dynamic, but I don't know how to get it dynmically.
Me.pvRegisterControlName.S etUserType (Enums.Use rType.Foru ms)
I have 5 user controls on the page, all the same control, but different display based on what value I passed into them, so I need to send that value.
thanks.
userControlName = "~/Modules/Login/Controls/
Dim userControl As Control = Page.LoadControl(userContr
userControl.ID = "pvRegister" & e.PageView.ID
e.PageView.Controls.Add(us
Now I want to call a function of that user control to set some values within it. How do I call a dynamically created control?
I know I could do it with this if it weren't dynamic, but I don't know how to get it dynmically.
Me.pvRegisterControlName.S
I have 5 user controls on the page, all the same control, but different display based on what value I passed into them, so I need to send that value.
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
At the top of your UserControl ascx page is a @Control directive. Post that so I can see it.
As for this one:
For Ctype(usercontrol.... : usercontrol is a type and cannot be used as an expression.
This was the code you had:
Dim userControl As Control = Page.LoadControl(userContr olName)
Is "userControl" the name of the variable here?
As for this one:
For Ctype(usercontrol.... : usercontrol is a type and cannot be used as an expression.
This was the code you had:
Dim userControl As Control = Page.LoadControl(userContr
Is "userControl" the name of the variable here?
One of the problems is we shouldnt be using userControl as a variable.
'Instead of this:
Dim userControl As Control = Page.LoadControl(userControlName)
userControl.ID = "pvRegister" & e.PageView.ID
e.PageView.Controls.Add(userControl)
'Do this:
Dim uc As Control = Page.LoadControl(userControlName)
uc.ID = "pvRegister" & e.PageView.ID
e.PageView.Controls.Add(uc)
'then convert it:
ASP.RegisterControl_ascx myControl = CType(uc, ASP.RegisterControl_ascx)
myControl.SetUserType(Enums.UserType.Forums)
ASKER
I still get the same error:
RegisterControl_ascx is not a member of ASP.
Do I need a specific Import that I am missing?
I am loading each control in a page view. Here's what I have:
Dim userControlName As String = String.Empty
userControlName = "~/Modules/Login/Controls/ RegisterCo ntrol.ascx "
Dim uc As Control = Page.LoadControl(userContr olName)
uc.ID = "pvRegister" & e.PageView.ID
e.PageView.Controls.Add(uc )
ASP.RegisterControl_ascx myControl = CType(uc, ASP.RegisterControl_ascx))
RegisterControl_ascx is not a member of ASP.
Do I need a specific Import that I am missing?
I am loading each control in a page view. Here's what I have:
Dim userControlName As String = String.Empty
userControlName = "~/Modules/Login/Controls/
Dim uc As Control = Page.LoadControl(userContr
uc.ID = "pvRegister" & e.PageView.ID
e.PageView.Controls.Add(uc
ASP.RegisterControl_ascx myControl = CType(uc, ASP.RegisterControl_ascx))
Post your @control directive.
ASKER
Please be more specific where I might find this?
I'm no longer registering it in the code in front.
I'm no longer registering it in the code in front.
ASKER
Do you mean this?
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="RegisterControl. ascx.vb"
Inherits="RegisterControl" %>
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="RegisterControl.
Inherits="RegisterControl"
Yes, thats it. Two questions:
1. Do you have RegisterControl inside of a namespace? If so, what is it.
2. What is the name of your project?
1. Do you have RegisterControl inside of a namespace? If so, what is it.
2. What is the name of your project?
ASKER
No, I don't believe I do have a RegisterControl inside a namespace.
And this is not a project, it is a website.
I have another question open about the difference between a project and website if you care to answer that one.
http://www.experts-exchang e.com/Prog ramming/La nguages/.N ET/Visual_ Studio_.NE T_2005/Q_2 3875122.ht ml
And this is not a project, it is a website.
I have another question open about the difference between a project and website if you care to answer that one.
http://www.experts-exchang
Well there is something funny about the namespace that is causing this problem. We did solve the problem of "For Ctype(usercontrol.... : usercontrol is a type and cannot be used as an expression" by changing your variable name from userControl to uc.
As for the namespace problem, if you could post the codebehind to your usercontrol, that would be a big help.
As for the namespace problem, if you could post the codebehind to your usercontrol, that would be a big help.
ASKER
I'll have to get back on this one. thanks.
ASKER
I'm never going to get back on this one I guess, so I'm just going to close it out.
thanks!
thanks!
ASKER
The first error I get is: RegisterControl_ascx is not a member of ASP.
The second is: mycontrol is not declared.
For Ctype(usercontrol.... : usercontrol is a type and cannot be used as an expression.
Did we want the name of my controlID there?
Sorry, none of it is working. :(