Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Embedding User Controls..

Embedding User Controls..

Scheduled Pinned Locked Moved ASP.NET
htmlwinformscomtutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pogowolf
    wrote on last edited by
    #1

    Is there a way to embed an user control IN a user control? For example: let's say you have a login ASPX and you have a Wrapper ASPX that displays a special DIV matrix for layout etc. What I'm looking to pull off is to embed the login.aspx into the wrapper.aspx so that the login form is wrapped inside the wrapper. is this even possible, with out haveing a class or something just return raw HTML to the wrapper? (which is how I'm doing it now, I'm just hoping there's an easier way) thanks!!!! -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com

    J 1 Reply Last reply
    0
    • P pogowolf

      Is there a way to embed an user control IN a user control? For example: let's say you have a login ASPX and you have a Wrapper ASPX that displays a special DIV matrix for layout etc. What I'm looking to pull off is to embed the login.aspx into the wrapper.aspx so that the login form is wrapped inside the wrapper. is this even possible, with out haveing a class or something just return raw HTML to the wrapper? (which is how I'm doing it now, I'm just hoping there's an easier way) thanks!!!! -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com

      J Offline
      J Offline
      Jakob Farian Krarup
      wrote on last edited by
      #2

      You can load a usercontrol dynamically using the Page's LoadControl method. So you just need some place to add the control. A PlaceHolder control is perfect for this. Drag the PlaceHolder on to the place where you want to load the user control. Then use the code

      Control userControl = Page.LoadControl("myUserControl.ascx");
      placeHolder1.Controls.Add(userControl);

      I don't think there's a limit to the nesting of usercontrols within usercontrols, but I could be wrong :rolleyes: Kind regards - Jakob :cool: Three kinds of people in the world: - Those who can count.. - Those who can't!

      P 1 Reply Last reply
      0
      • J Jakob Farian Krarup

        You can load a usercontrol dynamically using the Page's LoadControl method. So you just need some place to add the control. A PlaceHolder control is perfect for this. Drag the PlaceHolder on to the place where you want to load the user control. Then use the code

        Control userControl = Page.LoadControl("myUserControl.ascx");
        placeHolder1.Controls.Add(userControl);

        I don't think there's a limit to the nesting of usercontrols within usercontrols, but I could be wrong :rolleyes: Kind regards - Jakob :cool: Three kinds of people in the world: - Those who can count.. - Those who can't!

        P Offline
        P Offline
        pogowolf
        wrote on last edited by
        #3

        That will work!! thank you Jakob! -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com

        J 1 Reply Last reply
        0
        • P pogowolf

          That will work!! thank you Jakob! -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com

          J Offline
          J Offline
          Jakob Farian Krarup
          wrote on last edited by
          #4

          You're very welcome :-D - Jakob Three kinds of people in the world: - Those who can count.. - Those who can't!

          P 1 Reply Last reply
          0
          • J Jakob Farian Krarup

            You're very welcome :-D - Jakob Three kinds of people in the world: - Those who can count.. - Those who can't!

            P Offline
            P Offline
            pogowolf
            wrote on last edited by
            #5

            Well it kinda worked.. got be over one hurdel at least. =) would wouldn't happen to know how to dynamicly call an ascx from a static user control? LOL the idea is this.. I have a control that holds html that 'wrappes' the data being returned from specific controls. Like a login control, or a 'menu' control. This allows for a consent look across the site. Yes, I could just add the wrapper to each specific control..but why duplcat that code, which I dont' need to? so the thought was to have the master page call the wrapper.. the wrapper would then call the the log in control, and the whole thing is rendered. so currently, my masterpage does this: ========================== '// Hold the area where the wrapped controls will be rendered. Dim Area As ContentPlaceHolder = Master.FindControl("CreateMiddleColumn") '// Now add as many wrappers as needed. Dim Motd As Control = Page.LoadControl("~/SiteControls/Wrapper.ascx") Wrapper.RenderPage = "motd" '// which control to render Area.Controls.Add(Motd) ========================== So the Wrapper does this on page load: Select Case Wrapper.RenderPage.ToLower Case "motd" '// Message of the day. Dim Title As New MOTD Me.Title.Text = Title.title() Title = Nothing Dim Motd As Control = Page.LoadControl("~/SiteControls/MOTD.ascx") Me.Data.Controls.Add(Motd) Motd = Nothing Case "whatsnew" Dim Title As New MOTD Me.Title.Text = Title.title() Me.Title.Text = "What's New" Title = Nothing Dim Motd As Control = Page.LoadControl("~/SiteControls/Whatsnew.ascx") Me.Data.Controls.Add(Motd) Motd = Nothing End Select the problem is that the 'RenderPage' doesn't switch if I call the wrapper twice in a row.. would it just be easier to duplicat the wrapper HTML into each control? (though I really don't want to do that.. what if I need to change it? then I would need to update each control.. and there could be 50+) any thoughts or ideas? -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com

            J 1 Reply Last reply
            0
            • P pogowolf

              Well it kinda worked.. got be over one hurdel at least. =) would wouldn't happen to know how to dynamicly call an ascx from a static user control? LOL the idea is this.. I have a control that holds html that 'wrappes' the data being returned from specific controls. Like a login control, or a 'menu' control. This allows for a consent look across the site. Yes, I could just add the wrapper to each specific control..but why duplcat that code, which I dont' need to? so the thought was to have the master page call the wrapper.. the wrapper would then call the the log in control, and the whole thing is rendered. so currently, my masterpage does this: ========================== '// Hold the area where the wrapped controls will be rendered. Dim Area As ContentPlaceHolder = Master.FindControl("CreateMiddleColumn") '// Now add as many wrappers as needed. Dim Motd As Control = Page.LoadControl("~/SiteControls/Wrapper.ascx") Wrapper.RenderPage = "motd" '// which control to render Area.Controls.Add(Motd) ========================== So the Wrapper does this on page load: Select Case Wrapper.RenderPage.ToLower Case "motd" '// Message of the day. Dim Title As New MOTD Me.Title.Text = Title.title() Title = Nothing Dim Motd As Control = Page.LoadControl("~/SiteControls/MOTD.ascx") Me.Data.Controls.Add(Motd) Motd = Nothing Case "whatsnew" Dim Title As New MOTD Me.Title.Text = Title.title() Me.Title.Text = "What's New" Title = Nothing Dim Motd As Control = Page.LoadControl("~/SiteControls/Whatsnew.ascx") Me.Data.Controls.Add(Motd) Motd = Nothing End Select the problem is that the 'RenderPage' doesn't switch if I call the wrapper twice in a row.. would it just be easier to duplicat the wrapper HTML into each control? (though I really don't want to do that.. what if I need to change it? then I would need to update each control.. and there could be 50+) any thoughts or ideas? -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com

              J Offline
              J Offline
              Jakob Farian Krarup
              wrote on last edited by
              #6

              Hi PogoWolf I don't know whether you have sufficient static HTML wrappers lying around, so you don't want to do it all by creating ASCX files instead. But if you want to load a Web User Control dynamically from another Web User Control (WUC hereafter), then you have to store information about what should be loaded somewhere that the WUC can get to it. For example Session, ViewState, QueryString, etc. In that case there is no problem with for example loading the following variables in Session:

              Session["mainControl"] = "usercontrols/Comments.ascx";
              Session["subControl"] = "usercontrols/AddComment.ascx";

              Then the ASPX Page could just look in Session["mainControl"] for what WUC to load, and the "Comments.ascx" WUC could look in Session["subControl"] for what WUC to load inside itself. Hope this helps, otherwise ask again. Kind regards - Jakob :cool: Three kinds of people in the world: - Those who can count.. - Those who can't!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups