Results 1 to 3 of 3

Thread: Using a property to define layout in User Control

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Auckland, New Zealand
    Posts
    15

    Question Using a property to define layout in User Control

    I've been searching across the web but can't find the result to something that I imagine is easy to do.

    What I've got is a User Control with a property called Layout which can either Brief or Full. If Layout=Brief then I want it to display an ItemTemplate with a different table layout compared to the layout used if Layout=Full. Each template is signficantly different. However they need to access the same data so I thought it would surely make sense to use the one User Control.

    So basically, can I create 2 different templates and call the appropriate one depending on the property value.

    Thanks!

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Yes you can do this in the code behind of the user control. First declare a public string called Layout outside of any prodecure (right after class declaration is best):-

    Public String Layout

    Then when placing your user control set this property:-

    <udd:MyUserControl id="blah" runat="server" Layout="Brief" />

    Now in the Load event of the control you can check it:-

    If Layout="brief" then
    'brief implementation
    else
    'Full Implementation
    End If

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Auckland, New Zealand
    Posts
    15
    Thanks for your reply. That's what I did too. I've used the LoadTemplate method to load up the appropriate template depending on what Layout value was passed in through the property.

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width