Results 1 to 7 of 7

Thread: Separate dynamic controls with a "<br>"

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Resolved Separate dynamic controls with a "<br>"

    I'm adding controls to my page in code and needed <br> between the controls to put them on new lines. I just want to write <br>'s to the page without using the HtmlAnchor control. Is there a better way than this?
    Code:
    Label l1 = new Label();
    Label l2 = new Label();
    Label l3 = new Label();
    
    HtmlAnchor an1 = new HtmlAnchor();
    HtmlAnchor an2 = new HtmlAnchor();
    
    l1.Text = "Label1";
    l2.Text = "Label2";
    l3.Text = "Label3";
    
    an1.InnerHtml = an2.InnerHtml = "<br>";
    
    Page.Controls.Add(l1);
    Page.Controls.Add(an1);
    Page.Controls.Add(l2);
    Page.Controls.Add(an2);
    Page.Controls.Add(l3);
    Last edited by wey97; Apr 22nd, 2005 at 08:55 AM.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Separate dynamic controls with a "<br>"

    You could encapsulate the controls inside User Controls, and simply have a <br> appended in the HTML there.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: Separate dynamic controls with a "<br>"

    Quote Originally Posted by plenderj
    You could encapsulate the controls inside User Controls, and simply have a <br> appended in the HTML there.
    OK now I have the controls in a user control so how can I append the HTML? I still couldn't think of a better way than what I already have.

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Separate dynamic controls with a "<br>"

    Just right click and go into the HTML Source for the user control, and put <br> at the bottom of it
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: Separate dynamic controls with a "<br>"

    But the <br> needs to be loaded dynamically between every element inside the user control. I thought I could just use some sort of HTML writer to write between the elements on the page.

  6. #6
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Separate dynamic controls with a "<br>"

    Create a Generic Html Control HtmlControl namespace set it up as a <br> and add it between the controls.

    If it needs to be added for every added control override the add/added control member and do it there.
    Magiaus

    If I helped give me some points.

  7. #7
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Re: Separate dynamic controls with a "<br>"

    Take the time to scroll down your toolbox until you find the Literal Control. That control is rarely seen because you normally have to scroll down to it. You see, it literally outputs what you put into it. So, you can put html into it, and it spits it out into the response stream just as you had put it in the .Text property. This is useful if you want to display html content from a database, or do exactly what you want to do. Example:

    Code:
    Label l1 = new Label();
    Label l2 = new Label();
    Label l3 = new Label();
    
    LiteralControl lc1= new LiteralControl ();
    LiteralControl lc2= new LiteralControl ();
    
    l1.Text = "Label1";
    l2.Text = "Label2";
    l3.Text = "Label3";
    
    lc1.Text= lc2.Text= "<br>";
    
    Page.Controls.Add(l1);
    Page.Controls.Add(lc1);
    Page.Controls.Add(l2);
    Page.Controls.Add(lc2);
    Page.Controls.Add(l3);

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