Help with ASCX Issue!

  • Thread starter Thread starter Wade Beasley
  • Start date Start date
W

Wade Beasley

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.

Thanks,
Wade



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
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.

I'm no expert, but I did something similiar for a screen version vs. a
'print friendly' version.

What I did is put the options inside the individual controls. ie, the page
links to the same header and footer, but depending on a querystring, these
two ASCX files return different HTML.

With judicious use of CSS (taking a lot of the styling out of the app) this
might be a solution for you.

-Darrel
 
Wade Beasley said:
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.
 
Back
Top