Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   How to duplicate a user control on a page? (http://www.velocityreviews.com/forums/t771969-how-to-duplicate-a-user-control-on-a-page.html)

Ed Klein 12-05-2003 02:09 AM

How to duplicate a user control on a page?
 
I have a custom page-navigation control (similar to the one from the
DataGrid class) implemented as a UserControl. I'd like to place it at both
the top and bottom of the container that lists my data items, in the same
way that the DataGrid's "TopAndBottom" pager style works. I'm not using a
DataGrid, so I need to do this myself. The obvious way, which seems
tedious, is like this:

<MyNamespace:MyPager id="Pager1" runat="server" />
<MyNamespace:MyDataList id="MyList" runat="server" />
<MyNamespace:MyPager id="Pager2" runat="server" />

And in the code:

Pager1.PageSize = 10;
Pager2.PageSize = 10;
Pager1.CurPos = 30;
Pager2.CurPos = 30;
Pager1.DataBind();
Pager2.DataBind();

and so on. Both instances of "MyPager" look exactly the same and are
databound with exactly the same data. Seems like it would be easier to just
have one instance of the pager, but allow it to somehow render itself twice
on the containing page, so I wouldn't have to have all these duplicate lines
of code. Is this possible in ASP.NET?

--
Ed
egksf@earthlink.net




Mark Fitzpatrick 12-05-2003 02:41 PM

Re: How to duplicate a user control on a page?
 
Ed,
You could try doing this in code. Instead of your pager control,
create placeholder controls in the same place. Then programatticaly create a
single instance of your pager control. Then use the placeholder's
Controls.Add method to add the control to the placeholders (don't forget to
do it for each individual placeholder). Not sure if this will work, but it's
worth a shot.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Ed Klein" <egksf@earthlink.net> wrote in message
news:eiMddTtuDHA.2208@TK2MSFTNGP10.phx.gbl...
> I have a custom page-navigation control (similar to the one from the
> DataGrid class) implemented as a UserControl. I'd like to place it at

both
> the top and bottom of the container that lists my data items, in the same
> way that the DataGrid's "TopAndBottom" pager style works. I'm not using a
> DataGrid, so I need to do this myself. The obvious way, which seems
> tedious, is like this:
>
> <MyNamespace:MyPager id="Pager1" runat="server" />
> <MyNamespace:MyDataList id="MyList" runat="server" />
> <MyNamespace:MyPager id="Pager2" runat="server" />
>
> And in the code:
>
> Pager1.PageSize = 10;
> Pager2.PageSize = 10;
> Pager1.CurPos = 30;
> Pager2.CurPos = 30;
> Pager1.DataBind();
> Pager2.DataBind();
>
> and so on. Both instances of "MyPager" look exactly the same and are
> databound with exactly the same data. Seems like it would be easier to

just
> have one instance of the pager, but allow it to somehow render itself

twice
> on the containing page, so I wouldn't have to have all these duplicate

lines
> of code. Is this possible in ASP.NET?
>
> --
> Ed
> egksf@earthlink.net
>
>
>




Ed Klein 12-05-2003 09:43 PM

Re: How to duplicate a user control on a page?
 
Thanks for the suggestion. Apparently, though, ASP.NET doesn't allow a
single control instance to be rendered in more than one place on the page.
I tried your method but it only rendered the bottom pager; it's as if the
second invocation of "Controls.Add" had the side-effect of removing the
control from the first placeholder. No big deal; I'll just go back to two
pager instances and write a function that sets parameters for each, which
will at least eliminate some duplication.

--
Ed


"Mark Fitzpatrick" <markfitz@fitzme.copm> wrote in message
news:OabwV3zuDHA.640@tk2msftngp13.phx.gbl...
> Ed,
> You could try doing this in code. Instead of your pager control,
> create placeholder controls in the same place. Then programatticaly create

a
> single instance of your pager control. Then use the placeholder's
> Controls.Add method to add the control to the placeholders (don't forget

to
> do it for each individual placeholder). Not sure if this will work, but

it's
> worth a shot.
>
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP - FrontPage
>
> "Ed Klein" <egksf@earthlink.net> wrote in message
> news:eiMddTtuDHA.2208@TK2MSFTNGP10.phx.gbl...
> > I have a custom page-navigation control (similar to the one from the
> > DataGrid class) implemented as a UserControl. I'd like to place it at

> both
> > the top and bottom of the container that lists my data items, in the

same
> > way that the DataGrid's "TopAndBottom" pager style works. I'm not using

a
> > DataGrid, so I need to do this myself. The obvious way, which seems
> > tedious, is like this:
> >
> > <MyNamespace:MyPager id="Pager1" runat="server" />
> > <MyNamespace:MyDataList id="MyList" runat="server" />
> > <MyNamespace:MyPager id="Pager2" runat="server" />
> >
> > And in the code:
> >
> > Pager1.PageSize = 10;
> > Pager2.PageSize = 10;
> > Pager1.CurPos = 30;
> > Pager2.CurPos = 30;
> > Pager1.DataBind();
> > Pager2.DataBind();
> >
> > and so on. Both instances of "MyPager" look exactly the same and are
> > databound with exactly the same data. Seems like it would be easier to

> just
> > have one instance of the pager, but allow it to somehow render itself

> twice
> > on the containing page, so I wouldn't have to have all these duplicate

> lines
> > of code. Is this possible in ASP.NET?
> >
> > --
> > Ed
> > egksf@earthlink.net
> >
> >
> >

>
>





All times are GMT. The time now is 05:02 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.