I have attached a project which contain a webform including a placeholder. The placeholder is loaded with a user control. How do I activate a function in the user control from the webform?
Printable View
I have attached a project which contain a webform including a placeholder. The placeholder is loaded with a user control. How do I activate a function in the user control from the webform?
((UserControlClass)PlaceHolder.FindControl("UserControlID")).Method(); //C#
Great, I'm using VB, but it must be almost the same. I will try that, otherwise I'll get back :-)Quote:
Originally Posted by Magiaus
My palceholder is named plh1. When I apply this code
plh1.FindControl("Cond1Abs.ascx")
I'm not able to apply the function SetLanguage, that I want to call for the Cond1Abs.ascx? What am I doing wrong?
:confused:
try
vb
in C# it'll be like this (as in Magiaus earlier post)VB Code:
Ctype(plh1.FindControl("Cond1Abs"),Cond1Abs).Method()
Code:((Cond1Abs)plh1.FindControl("Cond1Abs")).method();
Hope this helps.
tsami
Still it returns
But maybe I'm doing something wrong. I have attached the entire project in my first thread, if youn can make it work, please let me know.Code:Object reference not set to an instance of an object.
You have to look for it by it's ID, not the file name. Make sure you are using the ID. I see in your post above you have the . ascx as part of your call to FindControl. The .ascx should not be there.
I looked at your code.Code:CType(PlaceHolder1.FindControl("WU1"), WebUserControl1).SomeText()
Hello Magiaus, thanks for your reply.Quote:
Originally Posted by Magiaus
Is the code working in the code, I have attatched? I still got the error when I implement the code:
Code:CType(PlaceHolder1.FindControl("WU1"), WebUserControl1).SomeText()
I don't know I didn't actually run your code or change it up any. I basicly just looked at it and looked at how you cast in VB.Net.
I don't know that much about VB.Net anymore. I started C# about 2 years ago and I refuse to go back to VB.Net and have subsequently erased all information regarding it....
If you have MSDN I recomend looking at Placeholder and it's implemetation of FindControl in your MSDN. Also I've never used a PlaceHolder I always use a Panel.