|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamically load webcontrolHi
I have a scenario where I have a webcontrol on an ASP.Net 2.0 page, in some cases I want to dynamically load another webcontrol instead of the control I have. I want to load one of several possible webcontrols instead, and I would like it to be so that I don't have to add a reference to all the possible alternate webcontrols. Is this possible? Kind Regards, Allan Ebdrup Page.Controls.Add() is your friend.
-- Show quoteHide quote-Demetri "Allan Ebdrup" wrote: > Hi > I have a scenario where I have a webcontrol on an ASP.Net 2.0 page, in some > cases I want to dynamically load another webcontrol instead of the control I > have. I want to load one of several possible webcontrols instead, and I > would like it to be so that I don't have to add a reference to all the > possible alternate webcontrols. > Is this possible? > > Kind Regards, > Allan Ebdrup > > > OK
Now I've tried the following: Create a control that's called DynamicLoad with a Label in it, and inserted it on an ASP page Now I want to swap the DynamicLoad control with another control, I try to find the control in Page.Controls like this: --- foreach(Control c in Page.Controls){ Response.Write("c.GetType:" + c.GetType().ToString() + "<br>"); But the output is:} --- --- c.GetType:System.Web.UI.LiteralControl c.GetType:System.Web.UI.HtmlControls.HtmlHead c.GetType:System.Web.UI.LiteralControl c.GetType:System.Web.UI.HtmlControls.HtmlForm c.GetType:System.Web.UI.LiteralControl --- So how do I find the DynamicLoad control and swap it, when Page.Controls contains the controls inside the DynamicLoad control? Kind Regards, Allan Ebdrup Now I've found the control I want to swap in the variable c, and I try to
execute the following: Page.Controls[Page.Controls.IndexOf(c)] = new System.Web.UI.HtmlControls.HtmlButton(); But I get an error that Page.Controls is read only, how do I swap the control? Is there some other event than Page_Load that allows you to modify Page.Controls? Kind Regards, Allan Ebdrup Now I've tried to override FrameworkInitialize, and the first thing I do in
my override is call base.FrameworkInitialize, but when I loop through the controls on the page I can't find the control I want to swap, it doesn't seem to be loaded yet. Kind Regards, Allan Ebdrup Found the problem, seems you cant change page.controls in the control, if i
do the swap in the main pages Page_Load there is no problem.
How to deselect item on single select listbox?
Where in the viewstate is a GridView's rows? Remove Dynamic User Controls from a collection I really need to get this working...... dropdownlists, their items and viewstate link on an entire row in a datagrid control exposing collection. HTML editor for Safari browser Customizing a TreeNode's viewstate DynamicMenuItemStyle override style (cursor:text) |
|||||||||||||||||||||||