[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Dynamically Including .ascx files at runtime

InfoCloud

1/24/2003 7:34:00 AM

The book i'm reading describes User Controls (.ascx files) as similar to
classic ASP include files.
I used to include files dynamically as I needed to improve on reuse.

The book i'm reading only shows me how to add the User Controls during
design time.
Is it possible to have a main page, that includes different User Controls at
runtime, depending upon what the user clicks on?
If so how would I do this?

For example,
The main page would display "Welcome page" User Control
When the user clicks a "MenuA" button on the nav bar, it would display "You
clicked Menu A" User Control.
When the user clicks a "MenuB" button on the nav bar, it would display "You
clicked Menu B" User Control.
And so on.

Thanks in advanced.
InfoCloud


4 Answers

unknown

1/24/2003 11:23:00 AM

0

within your Page object use this:

Control c = this.LoadControl( @"~\relativeFileName.ascx" );

Then add the control where you need it.

McGiv


"InfoCloud" <InfoCloud@nyc.rr.com> wrote in message
news:F75Y9.62414$yi6.9735410@twister.nyc.rr.com...
> The book i'm reading describes User Controls (.ascx files) as similar to
> classic ASP include files.
> I used to include files dynamically as I needed to improve on reuse.
>
> The book i'm reading only shows me how to add the User Controls during
> design time.
> Is it possible to have a main page, that includes different User Controls
at
> runtime, depending upon what the user clicks on?
> If so how would I do this?
>
> For example,
> The main page would display "Welcome page" User Control
> When the user clicks a "MenuA" button on the nav bar, it would display
"You
> clicked Menu A" User Control.
> When the user clicks a "MenuB" button on the nav bar, it would display
"You
> clicked Menu B" User Control.
> And so on.
>
> Thanks in advanced.
> InfoCloud
>
>


InfoCloud

1/24/2003 1:12:00 PM

0

I got a great article here:
http://www.codeproject.com/aspnet/aspnetuserco...

"McGiv" <nospam@nospam.com> wrote in message
news:u3hzWK5wCHA.2648@TK2MSFTNGP11...
> within your Page object use this:
>
> Control c = this.LoadControl( @"~\relativeFileName.ascx" );
>
> Then add the control where you need it.
>
> McGiv
>
>
> "InfoCloud" <InfoCloud@nyc.rr.com> wrote in message
> news:F75Y9.62414$yi6.9735410@twister.nyc.rr.com...
> > The book i'm reading describes User Controls (.ascx files) as similar to
> > classic ASP include files.
> > I used to include files dynamically as I needed to improve on reuse.
> >
> > The book i'm reading only shows me how to add the User Controls during
> > design time.
> > Is it possible to have a main page, that includes different User
Controls
> at
> > runtime, depending upon what the user clicks on?
> > If so how would I do this?
> >
> > For example,
> > The main page would display "Welcome page" User Control
> > When the user clicks a "MenuA" button on the nav bar, it would display
> "You
> > clicked Menu A" User Control.
> > When the user clicks a "MenuB" button on the nav bar, it would display
> "You
> > clicked Menu B" User Control.
> > And so on.
> >
> > Thanks in advanced.
> > InfoCloud
> >
> >
>
>


InfoCloud

1/24/2003 1:15:00 PM

0

Hello, my question relates to the following article:
Programatically include an ASP.NET UserControl in a Web Page
http://www.codeproject.com/aspnet/aspnetuserco...

It would be nice to have an example where a different Web User Control could
be loaded with different forms,
depending on the functionality the user requests on a Navbar. I wanted to
maximize code reuse by using Web User Controls.
I had worked hard to create a default.aspx page that has a HTML table that
centrally integrates all the Web User Controls together.
I had created a Web UserControl NavbarLeft with Link Buttons and a Web
UserControl MainPanel to be loaded depending on the Link Button that is
clicked. To my horror, I discovered that there is only 1 serverside form
per page.

I'm too tired to think of work arounds. Any suggestions for the proper way
to do this?

Help would be greatly appreciated.
Thanks in advanced.
InfoCloud


Constance J. Petersen

1/24/2003 4:25:00 PM

0

Hi InfoCloud,

The following article provides a tutorial, demo, and code that explains how to
construct a simple, visual Web page template that lets you control the look and
feel of all your Web pages using a single ASPX.

Creating a Visual Web Page Template
http://www.smart...articles/vb_temp...

The main content portion of each Web page is implemented as a standard user
control that inherits from a custom ControlBase class, which subclasses the
UserControl class. This allows you to provide common functionality within the
content portion of each page.

--
Constance Petersen
Build a great Web site: http://www.smart...
Learn ASP.NET: "Programming the Web with Visual Basic .NET"
http://amazon.com/exec/obidos/ASIN/1590590279/ref=nosim/constanc...


"InfoCloud" <InfoCloud@nyc.rr.com> wrote in message
news:G7aY9.62666$yi6.9774065@twister.nyc.rr.com...
> It would be nice to have an example where a different Web User Control could
> be loaded with different forms,
> depending on the functionality the user requests on a Navbar. I wanted to
> maximize code reuse by using Web User Controls.
> I had worked hard to create a default.aspx page that has a HTML table that
> centrally integrates all the Web User Controls together.
> I had created a Web UserControl NavbarLeft with Link Buttons and a Web
> UserControl MainPanel to be loaded depending on the Link Button that is
> clicked. To my horror, I discovered that there is only 1 serverside form
> per page.
>
> I'm too tired to think of work arounds. Any suggestions for the proper way
> to do this?