Embedding User Controls..
-
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
-
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
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!
-
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!
That will work!! thank you Jakob! -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com
-
That will work!! thank you Jakob! -== The PogoWolf ==- Like a funkey muckin' a bootfall. http://www.pogowolf.com GamersVue: ttp://GamersVue.blogger.com
You're very welcome :-D - Jakob Three kinds of people in the world: - Those who can count.. - Those who can't!
-
You're very welcome :-D - Jakob Three kinds of people in the world: - Those who can count.. - Those who can't!
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
-
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
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!