Problem using dynamic Datalist templates - Newbie

  • Thread starter dresde from NYC
  • Start date
D

dresde from NYC

Hi there!

Hopefully somebody can help as I am getting desperate.

I am using C# to develope a web user control containing a DataList and I
want my DataList to look different depending on some control properties.

To achieve that I use "Page.LoadTemplate (myTemplateName)". I do this on my
OnInit event to make sure my controls are created before LoadViewState etc
and avoid problems when posting back.

My problem is that I need to pass the name of the template to load during
OnInit. Therefore I cannot use the control properties yet. Any idea how to do
this? I have read all the articles about dynamic controls etc but I can't
find anything :(

Any help/hint/suggestion/comment/question will be greatly appreciated :)

Thanks in advance!

Diana Carrasco, NYC
 
D

dresde from NYC

Hi!

Just wanted to let you know I have solved the problem.

I now create my control dynamically using LoadControl and AddControl. Just
before calling AddControl I set the value of one of the control properties.
It works!

It would look like this:

=======================================================

protected System.Web.UI.Control ctl1;

ctl1 = LoadControl("myTestControl.ascx");

((myTestControl)ctl1).myTemplate = this.myTemplate;

myPlaceHolder.Controls.Add(ctl1);

=======================================================

Cheers,

Diana.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top