PDA

Click to See Complete Forum and Search --> : Call function in user control placed in placeholder?


hpl
Jul 7th, 2005, 01:04 AM
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?

Magiaus
Jul 7th, 2005, 12:56 PM
((UserControlClass)PlaceHolder.FindControl("UserControlID")).Method(); //C#

hpl
Jul 7th, 2005, 04:04 PM
((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 :-)

hpl
Jul 8th, 2005, 01:00 AM
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:

Sami Antero
Jul 8th, 2005, 02:25 AM
try
vb
Ctype(plh1.FindControl("Cond1Abs"),Cond1Abs).Method()
in C# it'll be like this (as in Magiaus earlier post)
((Cond1Abs)plh1.FindControl("Cond1Abs")).method();


Hope this helps.
tsami

hpl
Jul 8th, 2005, 02:45 AM
Still it returns

Object reference not set to an instance of an object.


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.

Magiaus
Jul 8th, 2005, 07:01 AM
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.

Magiaus
Jul 8th, 2005, 07:13 AM
I looked at your code. CType(PlaceHolder1.FindControl("WU1"), WebUserControl1).SomeText()

hpl
Jul 11th, 2005, 01:51 AM
I looked at your code. CType(PlaceHolder1.FindControl("WU1"), WebUserControl1).SomeText()

Hello Magiaus, thanks for your reply.
Is the code working in the code, I have attatched? I still got the error when I implement the code:

CType(PlaceHolder1.FindControl("WU1"), WebUserControl1).SomeText()

Magiaus
Jul 11th, 2005, 08:53 AM
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.