Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2005, 04:42 PM
Registered User
 
Join Date: May 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default User Control within Custom Server Controls

Is it possible to use a user control in a custom server control? If so, how is it rendered to the browser?

Thanks in advance!

 
Old April 13th, 2005, 07:34 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

A user control lives as an ASCX file in the web project so it wouldn't normally be used in a compiled control. However... you could create an instance of such a control. The Page class has a method 'LoadControl' which takes a file as an argument. This will load an instance of a control that you could then add to a controls collection inside your custom control. Keep in mind however, that you will run into a potential problem with this: if the compiled control is in a different assembly and you need to reference the class type that represents the user control (the code behind the ASCX) you'll end up with a circular reference. Also in my opinion, by doing this you are kind of breaking the rules of building a custom server control by making it dependant on an external resource that you can't directly supply. The consumer of the custom control will have to have the user control file in their web project.

-Peter
 
Old April 15th, 2005, 07:37 AM
Registered User
 
Join Date: May 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My server control renders a table with x number of rows. I want to add a user control to each row of the table, last column. I do not know how many user controls I will need until runtime. How do I specify where the user control is placed in the server control's table cell?

 
Old April 15th, 2005, 09:00 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to add it to the last column's cell's Controls collection in the appropriate order. As long as it's in the controls collection .NET will render it.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM
DataGrid Controls Within custom validator control geetha_ganesan ADO.NET 1 March 26th, 2005 04:38 PM
urgent custom control with collection of controls dd_smith Pro VB.NET 2002/2003 1 December 19th, 2004 06:05 PM
custom server controls rotsey General .NET 0 November 24th, 2004 03:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.