Help with Page.LoadControl(Type t, Object[] parameters)

  • Thread starter Thread starter Guest 20221009
  • Start date Start date
G

Guest 20221009

Guest
I have done very little Webforms dev ever since MVC beta came out and I am battling to load a user control with parameters.

I have a UseControl for handling comments need to add this via code based on certain conditions. What does this method expect as the Type. I have searched and I m yet to find a good resource on this.


Control ContentComments = Page.LoadControl(contentType, parameters);

:cry:
 
Got it to work this way.

Code:
   ChildContent ContentComments = new ChildContent();
                        ContentComments = Page.LoadControl("~/Controls/ChildContent.ascx") as ChildContent;

                        ContentComments.contentID = contentID;
                        ContentComments.ContentBody = ContentBody;

                        ContentComments.ID = "LinkedContent" + i.ToString();                        
                        
                        PlaceHolder1.Controls.Add(ContentComments);

I am pretty chuffed, but my Webforms skills suck badly these days.
 
Well done. It had crossed my mind to set parameters after the fact, and there you go. :)
 
Well done. It had crossed my mind to set parameters after the fact, and there you go. :)
Haha! Would've suggested that if I read this thread earlier. User controls come in real handy in an AJAX / Web Service environment when you can render the output to HTML, if you extend the Page class a bit to allow for that. :) I somehow find myself still enjoying Web Forms (albeit my own severely butchered, quasi-MVC form) more than the "proper" MVC framework provided by Microsoft. I guess old habits die hard...
 
Top
Sign up to the MyBroadband newsletter
X