Dynamicly create table once

Discussion in 'ASP .Net Web Controls' started by Tony, Feb 20, 2005.

  1. Tony

    Tony Guest

    win xp - vs 2002 - vb - web forms

    I have this code in the page_load event.
    works fine except, I put it all in an if not ispostback then.
    I don't want to run all this code (will get much bigger) each round trip.
    The table disappears on each round trip, unless I leave it out of the not
    isposback.
    Anyway to create once or do I have to run this code each round trip?

    Thanks Tony

    table.Visible = True
    table.BackColor = Color.Ivory
    table.GridLines = GridLines.Both
    table.Visible = True

    For rowloop = 0 To 5
    Dim trow As New TableRow()
    For cellsloop = 0 To 2
    Dim tcell As New TableCell()
    trow.Cells.Add(tcell)
    Next cellsloop
    table.Rows.Add(trow)
    table.Rows(rowloop).Cells(0).VerticalAlign =
    VerticalAlign.Middle
    table.Rows(rowloop).Cells(0).Width() = Unit.Pixel(200)
    table.Rows(rowloop).Cells(1).Width() = Unit.Pixel(200)
    table.Rows(rowloop).Height = Unit.Percentage(100)
    table.Rows(rowloop).Cells(0).Wrap = True
    Next rowloop

    labFirstName.Text = "Enter Frist Name"
    table.Rows(0).Cells(0).Controls.Add(labFirstName)

    labLastName.Text = "Enter Last Name"
    table.Rows(1).Cells(0).Controls.Add(labLastName)

    labEMail.Text = "Enter E-Mail Address"
    table.Rows(2).Cells(0).Controls.Add(labEMail)

    table.Rows(0).Cells(1).Controls.Add(txtFirstName)
    table.Rows(1).Cells(1).Controls.Add(txtLastName)
    table.Rows(2).Cells(1).Controls.Add(txtEMail)

    Page.Controls(1).Controls.Add(table)


    table.Style.Add("10", "Z-INDEX: 101; LEFT: 150px; POSITION:
    absolute; TOP: 150px")
    Tony, Feb 20, 2005
    #1
    1. Advertising

  2. Tony

    Wilco Bauwer Guest

    After each postback (or roundtrip if you like), the control hierarchy
    is created "from scratch". If you add a control to the Controls
    collection, you do this for the _current request only_. After the next
    roundtrip you have to READD this control again. So when dealing with
    dynamically created controls, you should NOT check if the request is a
    postback. Such checks should generally be done ONLY to avoid
    unnecessary roundtrips to a resource such as a DB, when the data is
    already in place (due to the viewstate).

    In your case you probably want to create a composite control and put
    the control creation in CreateChildControls.
    Wilco Bauwer, Feb 20, 2005
    #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. Kristof Pauwels
    Replies:
    1
    Views:
    408
    Rahul Singh
    Jul 27, 2003
  2. Adam
    Replies:
    2
    Views:
    430
    dontlikenicknames
    Sep 2, 2008
  3. Lionel LASKE

    Customize munged URL or dynamicly create Session

    Lionel LASKE, May 24, 2006, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    756
    Lionel LASKE
    May 24, 2006
  4. paula
    Replies:
    1
    Views:
    240
    Bob Barrows [MVP]
    Nov 8, 2005
  5. Gancy
    Replies:
    4
    Views:
    163
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page