Problem using dynamic Datalist templates - Newbie

Discussion in 'ASP .Net Building Controls' started by dresde from NYC, Dec 9, 2004.

  1. 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
    dresde from NYC, Dec 9, 2004
    #1
    1. Advertising

  2. 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.
    dresde from NYC, Dec 10, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,846
  2. =?Utf-8?B?UmFwaA==?=

    Using templates..problem with DataList

    =?Utf-8?B?UmFwaA==?=, Nov 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    321
    =?Utf-8?B?UmFwaA==?=
    Nov 1, 2004
  3. John Harrison

    using templates in templates

    John Harrison, Jul 31, 2003, in forum: C++
    Replies:
    8
    Views:
    373
    Torsten Curdt
    Jul 31, 2003
  4. JKop
    Replies:
    3
    Views:
    451
  5. recover
    Replies:
    2
    Views:
    785
    recover
    Jul 25, 2006
Loading...

Share This Page