dynamically loading usercontrol
dynamically loading usercontrol
am 23.01.2008 06:09:09 von param
Hello all,
I have a UserControl that renders some HTML content. I now need to
dynamically load and render "n" instances of this usercontrol on a host aspx
page inside a panel control based upon user input of "n". Any ideas how I
can do this?
TIA!
Re: dynamically loading usercontrol
am 23.01.2008 09:45:44 von Eliyahu Goldin
You need to use a databound control, perhaps a repeater, that will be bound
to a datasource, perhaps an array, containing all instances of the user
control.
Have some code that will creat an array myControls[] based on the user
input. Then do
myRepeater.DataSource = myControls;
myRepeater.DataBind();
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
wrote in message
news:e$cBt4XXIHA.1164@TK2MSFTNGP02.phx.gbl...
> Hello all,
>
> I have a UserControl that renders some HTML content. I now need to
> dynamically load and render "n" instances of this usercontrol on a host
> aspx page inside a panel control based upon user input of "n". Any ideas
> how I can do this?
>
> TIA!
>
RE: dynamically loading usercontrol
am 23.01.2008 21:37:02 von mily242
Howdy,
Use Repeater or DataList:
-- aspx code --
-- c# code beside --
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int rowCount = 10;
myRepeater.DataSource = new int[rowCount];
myRepeater.DataBind();
}
}
Hope it helps
--
Milosz
"param@community.nospam" wrote:
> Hello all,
>
> I have a UserControl that renders some HTML content. I now need to
> dynamically load and render "n" instances of this usercontrol on a host aspx
> page inside a panel control based upon user input of "n". Any ideas how I
> can do this?
>
> TIA!
>
>
>
Re: dynamically loading usercontrol
am 24.01.2008 00:34:56 von param
OK,
Thanks for the tip. Now, what if I need to set custom properties on my
usercontrol. Is that possible?
TIA!
"Milosz Skalecki [MCAD]" wrote in message
news:B89DDECD-A644-4935-AC3C-1501108EB518@microsoft.com...
> Howdy,
>
> Use Repeater or DataList:
>
> -- aspx code --
>
>
>
>
>
> -- c# code beside --
> protected void Page_Load(object sender, EventArgs e)
> {
> if (!IsPostBack)
> {
> int rowCount = 10;
> myRepeater.DataSource = new int[rowCount];
> myRepeater.DataBind();
> }
> }
>
> Hope it helps
> --
> Milosz
>
>
> "param@community.nospam" wrote:
>
>> Hello all,
>>
>> I have a UserControl that renders some HTML content. I now need to
>> dynamically load and render "n" instances of this usercontrol on a host
>> aspx
>> page inside a panel control based upon user input of "n". Any ideas how I
>> can do this?
>>
>> TIA!
>>
>>
>>
Re: dynamically loading usercontrol
am 24.01.2008 19:37:01 von mily242
Howdy,
Yes it is, two ways:
1. through data binding:
2. or in the code behind:
OnItemDataBound="dynamicControls_ItemDataBound">
-- c# code behind --
protected void dynamicControls_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if (item.ItemType == ListItemType.Item ||
item.ItemType == ListItemType.AlternatingItem)
{
MyUserControl ctrl = (MyUserControlClassName)
item.FindControl("userControl");
ctrl.CustomDateProperty = DateTime.Now;
}
}
HTH
--
Milosz
"param@community.nospam" wrote:
> OK,
>
> Thanks for the tip. Now, what if I need to set custom properties on my
> usercontrol. Is that possible?
>
> TIA!
>
> "Milosz Skalecki [MCAD]" wrote in message
> news:B89DDECD-A644-4935-AC3C-1501108EB518@microsoft.com...
> > Howdy,
> >
> > Use Repeater or DataList:
> >
> > -- aspx code --
> >
> >
> >
> >
> >
> > -- c# code beside --
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > if (!IsPostBack)
> > {
> > int rowCount = 10;
> > myRepeater.DataSource = new int[rowCount];
> > myRepeater.DataBind();
> > }
> > }
> >
> > Hope it helps
> > --
> > Milosz
> >
> >
> > "param@community.nospam" wrote:
> >
> >> Hello all,
> >>
> >> I have a UserControl that renders some HTML content. I now need to
> >> dynamically load and render "n" instances of this usercontrol on a host
> >> aspx
> >> page inside a panel control based upon user input of "n". Any ideas how I
> >> can do this?
> >>
> >> TIA!
> >>
> >>
> >>
>
>
>
Re: dynamically loading usercontrol
am 27.01.2008 18:47:54 von param
Thank you.
"Milosz Skalecki [MCAD]" wrote in message
news:2F210E41-74AA-4E21-96DF-9163DA88EE10@microsoft.com...
> Howdy,
>
> Yes it is, two ways:
> 1. through data binding:
>
>
>
>
>
>
>
> 2. or in the code behind:
>
> OnItemDataBound="dynamicControls_ItemDataBound">
>
>
>
>
> -- c# code behind --
>
> protected void dynamicControls_ItemDataBound(object sender,
> RepeaterItemEventArgs e)
> {
> RepeaterItem item = e.Item;
>
> if (item.ItemType == ListItemType.Item ||
> item.ItemType == ListItemType.AlternatingItem)
> {
> MyUserControl ctrl = (MyUserControlClassName)
> item.FindControl("userControl");
>
> ctrl.CustomDateProperty = DateTime.Now;
> }
>
> }
>
> HTH
> --
> Milosz
>
>
> "param@community.nospam" wrote:
>
>> OK,
>>
>> Thanks for the tip. Now, what if I need to set custom properties on my
>> usercontrol. Is that possible?
>>
>> TIA!
>>
>> "Milosz Skalecki [MCAD]" wrote in message
>> news:B89DDECD-A644-4935-AC3C-1501108EB518@microsoft.com...
>> > Howdy,
>> >
>> > Use Repeater or DataList:
>> >
>> > -- aspx code --
>> >
>> >
>> >
>> >
>> >
>> > -- c# code beside --
>> > protected void Page_Load(object sender, EventArgs e)
>> > {
>> > if (!IsPostBack)
>> > {
>> > int rowCount = 10;
>> > myRepeater.DataSource = new int[rowCount];
>> > myRepeater.DataBind();
>> > }
>> > }
>> >
>> > Hope it helps
>> > --
>> > Milosz
>> >
>> >
>> > "param@community.nospam" wrote:
>> >
>> >> Hello all,
>> >>
>> >> I have a UserControl that renders some HTML content. I now need to
>> >> dynamically load and render "n" instances of this usercontrol on a
>> >> host
>> >> aspx
>> >> page inside a panel control based upon user input of "n". Any ideas
>> >> how I
>> >> can do this?
>> >>
>> >> TIA!
>> >>
>> >>
>> >>
>>
>>
>>