Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a user control to the form in code behind

Status
Not open for further replies.

bstineman

Programmer
Mar 19, 2003
9
US
I use a special class to handle page templating (we'll call this class "BasePage"). This works all well and good. Now I'm trying to take it to the next level by creating a "PageHeader" user control. I can create this control and it appears to work fine.

But... What I need to do is have BasePage create an instance of PageHeader and then render it. So far, I haven't had any luck getting any outpost whatsoever dispite knowing that PageHeader exists and Visible=True. I am calling its RenderControl method with the correct HTMLWriter. Just nothing appearing on the final page.

Any hints?
 
Ok, I initially got this to work by using the Page.LoadControl method to essentially connect the control to its ascx file.

Now I'm trying to put the control in its own control library so that other projects within the solution can referrence this common control.

Any help would be appreciated. :)
 
bstineman,

This is just a suggestion (based on personal experience)...

After a lot of thought and debating about this issue during my own adventures, I personally steered right away from user controls and went to developing custom server controls. True, user controls are way easier to develop and server controls are generally a pain in the arse but when it come down to it (_especially_ when developing libraries) the one thing that you have to think about is <tadaaaa!>: Reuseability.

With user controls, you have to distribute the .ascx file as well as the associated .dll. Users of these controls must then find their way into loading them into their projects (Oh yeah - and for every user control you distribute, it's a new .ascx and .dll file). If you create a server control, you can pack as many controls into a single .dll and distribute that one file. Users are then able to reference the control and add it to their projects by simply setting a reference to it and adding it to their toolboxes.

Hope this made sense to you and didn't throw you for too much of a loop. Good luck!

-----------------------------------------------
&quot;The night sky over the planet Krikkit is the least interesting sight in the entire universe.&quot;
-Hitch Hiker's Guide To The Galaxy
 
Ok, the question still remains then, how do I get the control to render its corresponding ascx file....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top