"Wade Beasley" <wa**********@i nsightbb.com> wrote in message
news:eL******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a web project that currently has a standard header, footer, and
menu ascx files. I am now suppose to change the project to allow a
user to choose from 3 different views, ie 3 different groups of those
ascx files. Does anyone have some sample code on how to do this?
This needs to check once a user has signed in on which version to
display.
You can use LoadControl to load the proper version of the .ascx file. The
following example is ripped off from Microsoft, then modified a bit:
private string whichView;
// When this page is loaded, it uses the TemplateControl .LoadControl
// method to programmaticall y create a user control. The user control
// is contained in the .ascx file that is passed as a parameter
// in the LoadControl call. The page then adds the control to its
// ControlCollecti on.
void Page_Load(objec t sender, System.EventArg s e)
{
// Obtain the UserControl object MyHeader from the
// user control file MyHeader_*.ascx .
if (!User.IsAuthen ticated)
whichView = "default";
Control myHeader= LoadControl(whi chView + "_MyHeader.ascx ");
Controls.Add(my Header);
}
You might then have default_MyHeade r.ascx, wide_MyHeader.a scx, and
green_MyHeader. ascx, depending on the value of whichView. You could do the
same with your footer and menu files.
--
John Saunders
johnwsaundersii i at hotmail