Results 1 to 10 of 10

Thread: Call function in user control placed in placeholder?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Call function in user control placed in placeholder?

    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?
    Attached Files Attached Files

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Call function in user control placed in placeholder?

    ((UserControlClass)PlaceHolder.FindControl("UserControlID")).Method(); //C#
    Magiaus

    If I helped give me some points.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Re: Call function in user control placed in placeholder?

    Quote Originally Posted by Magiaus
    ((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 :-)

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Re: Call function in user control placed in placeholder?

    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?

  5. #5
    Junior Member Sami Antero's Avatar
    Join Date
    Jun 2005
    Location
    Helsinki, Finland
    Posts
    16

    Re: Call function in user control placed in placeholder?

    try
    vb
    VB Code:
    1. Ctype(plh1.FindControl("Cond1Abs"),Cond1Abs).Method()
    in C# it'll be like this (as in Magiaus earlier post)
    Code:
    ((Cond1Abs)plh1.FindControl("Cond1Abs")).method();

    Hope this helps.
    tsami
    Last edited by Sami Antero; Jul 8th, 2005 at 02:26 AM. Reason: typos
    Sami Antero
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    no smileys, no funky certificates. Sorry.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Re: Call function in user control placed in placeholder?

    Still it returns
    Code:
    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.
    Last edited by hpl; Jul 8th, 2005 at 02:51 AM.

  7. #7
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Call function in user control placed in placeholder?

    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

    If I helped give me some points.

  8. #8
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Call function in user control placed in placeholder?

    I looked at your code.
    Code:
    CType(PlaceHolder1.FindControl("WU1"), WebUserControl1).SomeText()
    Magiaus

    If I helped give me some points.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Re: Call function in user control placed in placeholder?

    Quote Originally Posted by Magiaus
    I looked at your code.
    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:
    Code:
    CType(PlaceHolder1.FindControl("WU1"), WebUserControl1).SomeText()

  10. #10
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Call function in user control placed in placeholder?

    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.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width