Hi All,
I need to load varying Custome controls to one page with differnt panles,I have to load Custom control page according to selection of Criteria.
Thanks
Hi All,
I need to load varying Custome controls to one page with differnt panles,I have to load Custom control page according to selection of Criteria.
Thanks
Quick, practical pattern for ’s scenario (20 custom section controls, admin picks a subset): treat each section as an ASCX user control and load only the selected ones into a PlaceHolder at page init. That keeps markup small, lets each section encapsulate its own logic, and works much better than hard-wiring 20 panels. As pointed out, toggling panels is fine for a few fixed blocks; for many optional sections dynamic LoadControl is cleaner. ’s WPF comment applies to desktop apps — for ASP.NET WebForms use the LoadControl approach below.
Here is a minimal pattern to follow (ASPX placeholder + C# in code-behind):
<asp:PlaceHolder ID="phSections" runat="server" /> protected override void OnInit(EventArgs e)
{
base.OnInit(e);
var sections = GetSelectedSectionsForClient(); // e.g. ["Profile","Orders","Notes"]
foreach (var key in sections)
{
// Map keys to allowed file names instead of concatenating user input
string file = MapKeyToFile(key); // e.g. "Profile.ascx"
var ctl = LoadControl("~/Controls/" + file);
ctl.ID = "sec_" + key; // stable unique ID required for ViewState/events
phSections.Controls.Add(ctl);
// optional: wire an interface-based contract for page<->control comms
var contract = ctl as ISectionControl;
if (contract != null) contract.Initialize(contextObject);
}
} Troubleshooting and best practices: always recreate the same controls with the same IDs on every postback and do it in OnInit (or Page_Init) so viewstate and event wiring work. If controls must raise postback events, subscribe immediately after LoadControl. For performance, disable ViewState inside controls that don’t need it, cache rendered HTML for common selections, or lazy-load heavy sections with an AJAX call. Security: never build file paths from raw input — use a whitelist/dictionary (MapKeyToFile) to avoid path traversal.
If the page still feels heavy, render the initial set server-side and load rarely-used sections on demand via AJAX. This pattern balances scalability, maintainability, and predictable lifecycle behavior.
Jump to Post— Ketsuekiame 860Are you using WPF or Winforms? Only ever succeeded doing this in the former.
Are you using WPF or Winforms? Only ever succeeded doing this in the former.
Do you mean you want to show a particular panel depending on the user OR do you want different panels which the user can switch between.
If it's the first option simply use panels and show and hide them as is required.
If It's the latter you should use the tabpage control.
To Ketsuekiame, I am not using WPF out there.. this is just a normal conrols in asp.net.
To ChrisHunter, Let me Expalin: Look, I Have 20 Custom Control pages called sections..
let's take one scenario-admin user has selected 10 Sections. so as do admin selected only 10. client can able to see those selected sections.Rest of the sections will not be appear but here the problem is i am using custom controls for those sections and i have to load those section based on admin selection and it will appear into client screen.
hope i am clear.
Thanks guys for ur reply..
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.