Passing Parameters to User Controls that are Dynamically Loaded in Placeholders

Discussion in 'ASP .Net Building Controls' started by Josh, May 26, 2004.

  1. Josh

    Josh Guest

    Hi Guys,

    I have been having a big problem with trying to pass parameters into a
    user control when the user control is dynamically loaded into a
    placholder. I am developing in c#. I have get and set methods on the
    user control "editButton.ascx" which work fine.

    How do i pass parameter into the user controls "c1", "c2" ?

    Here is a bit of my code that is calling the user control from the
    aspx page.
    public void setupTemplate(string PID)
    {
    //load control into a placeholder
    UserControl c1 = (UserControl) LoadControl
    System.Configuration.ConfigurationSettings.AppSettings["virtualPath"]
    + "editButton.ascx");
    UserControl c2 = (UserControl)
    LoadControl(System.Configuration.ConfigurationSettings.AppSettings["virtualPath"]
    + "editButton.ascx");

    //PLACEHOLDER 1
    PlaceHolder phPlaceHolder =
    (PlaceHolder)this.FindControl("Form1").FindControl("PlaceHolder1");
    phPlaceHolder.Controls.Clear();
    phPlaceHolder.Controls.Add(c1);
    //PLACEHOLDER 2
    PlaceHolder phPlaceHolder2 =
    (PlaceHolder)this.FindControl("Form1").FindControl("PlaceHolder2");
    phPlaceHolder2.Controls.Clear();
    phPlaceHolder2.Controls.Add(c2);
    }

    Any help would be greatly appreciated.

    Thanks, Josh
    Josh, May 26, 2004
    #1
    1. Advertising

  2. Josh

    Sam Guest

    Hi,

    Just cast it to the appropriate type, ie. instead of (UserControl) put
    (editButton) or whatever you called the extended class in
    editButton.ascx.

    -Sam

    (Josh) wrote in message news:<>...
    > Hi Guys,
    >
    > I have been having a big problem with trying to pass parameters into a
    > user control when the user control is dynamically loaded into a
    > placholder. I am developing in c#. I have get and set methods on the
    > user control "editButton.ascx" which work fine.
    >
    > How do i pass parameter into the user controls "c1", "c2" ?
    >
    > Here is a bit of my code that is calling the user control from the
    > aspx page.
    > public void setupTemplate(string PID)
    > {
    > //load control into a placeholder
    > UserControl c1 = (UserControl) LoadControl
    > System.Configuration.ConfigurationSettings.AppSettings["virtualPath"]
    > + "editButton.ascx");
    > UserControl c2 = (UserControl)
    > LoadControl(System.Configuration.ConfigurationSettings.AppSettings["virtualPath"]
    > + "editButton.ascx");
    >
    > //PLACEHOLDER 1
    > PlaceHolder phPlaceHolder =
    > (PlaceHolder)this.FindControl("Form1").FindControl("PlaceHolder1");
    > phPlaceHolder.Controls.Clear();
    > phPlaceHolder.Controls.Add(c1);
    > //PLACEHOLDER 2
    > PlaceHolder phPlaceHolder2 =
    > (PlaceHolder)this.FindControl("Form1").FindControl("PlaceHolder2");
    > phPlaceHolder2.Controls.Clear();
    > phPlaceHolder2.Controls.Add(c2);
    > }
    >
    > Any help would be greatly appreciated.
    >
    > Thanks, Josh
    Sam, May 26, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josh
    Replies:
    1
    Views:
    9,545
    Jeffrey Palermo [MCP]
    May 26, 2004
  2. Sinisa Ruzin
    Replies:
    0
    Views:
    862
    Sinisa Ruzin
    Oct 7, 2004
  3. Replies:
    3
    Views:
    4,053
  4. JB McMichael
    Replies:
    0
    Views:
    384
    JB McMichael
    Jul 26, 2005
  5. Josh
    Replies:
    1
    Views:
    247
Loading...

Share This Page