"Wade Beasley" <wa**********@insightbb.com> wrote in message
news:eL****************@TK2MSFTNGP09.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 programmatically 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
// ControlCollection.
void Page_Load(object sender, System.EventArgs e)
{
// Obtain the UserControl object MyHeader from the
// user control file MyHeader_*.ascx.
if (!User.IsAuthenticated)
whichView = "default";
Control myHeader= LoadControl(whichView + "_MyHeader.ascx");
Controls.Add(myHeader);
}
You might then have default_MyHeader.ascx, wide_MyHeader.ascx, and
green_MyHeader.ascx, depending on the value of whichView. You could do the
same with your footer and menu files.
--
John Saunders
johnwsaundersiii at hotmail