Consecutive Additions of Controls

Discussion in 'ASP .Net' started by Matthew MacDonald, Aug 24, 2004.

  1. Hi all,
    I'm trying to make a web form that will allow the user to continuously add
    options to a form by clicking a button.

    Here is my sample code.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click

    Dim drop As New DropDownList



    tblMain.Rows(13).Cells(1).Controls.Add(drop)

    End Sub

    I want this to keep adding new drop down lists to the table whenever the
    user clicks the button. What happens, however, is that the page reloads and
    only one new control is ever added to the page (or more exactly, the
    previous new control is wiped out and a new one is added, thus only ever
    having one)


    Any ideas on this??

    Thanks, Matt
    Matthew MacDonald, Aug 24, 2004
    #1
    1. Advertising

  2. Matthew MacDonald

    bruce barker Guest

    you have to re-add dynamic controls on postback, so you will need to
    remember that you added them.

    -- bruce (sqlwork.com)


    "Matthew MacDonald" <> wrote in message
    news:...
    > Hi all,
    > I'm trying to make a web form that will allow the user to continuously

    add
    > options to a form by clicking a button.
    >
    > Here is my sample code.
    >
    > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    >
    > Dim drop As New DropDownList
    >
    >
    >
    > tblMain.Rows(13).Cells(1).Controls.Add(drop)
    >
    > End Sub
    >
    > I want this to keep adding new drop down lists to the table whenever the
    > user clicks the button. What happens, however, is that the page reloads

    and
    > only one new control is ever added to the page (or more exactly, the
    > previous new control is wiped out and a new one is added, thus only ever
    > having one)
    >
    >
    > Any ideas on this??
    >
    > Thanks, Matt
    >
    >
    bruce barker, Aug 24, 2004
    #2
    1. Advertising

  3. I figured as much.

    Any ideas on a good way to accomplish that?

    "bruce barker" <> wrote in message
    news:...
    > you have to re-add dynamic controls on postback, so you will need to
    > remember that you added them.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Matthew MacDonald" <> wrote in message
    > news:...
    > > Hi all,
    > > I'm trying to make a web form that will allow the user to continuously

    > add
    > > options to a form by clicking a button.
    > >
    > > Here is my sample code.
    > >
    > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > > System.EventArgs) Handles Button1.Click
    > >
    > > Dim drop As New DropDownList
    > >
    > >
    > >
    > > tblMain.Rows(13).Cells(1).Controls.Add(drop)
    > >
    > > End Sub
    > >
    > > I want this to keep adding new drop down lists to the table whenever the
    > > user clicks the button. What happens, however, is that the page reloads

    > and
    > > only one new control is ever added to the page (or more exactly, the
    > > previous new control is wiped out and a new one is added, thus only ever
    > > having one)
    > >
    > >
    > > Any ideas on this??
    > >
    > > Thanks, Matt
    > >
    > >

    >
    >
    Matthew MacDonald, Aug 24, 2004
    #3
  4. Matthew MacDonald

    Karl Guest

    Tables don't maintain their state in postback. You can track how often a
    row has been added in viewstate and add that amount:

    dim count as integer = 0
    if not ViewState("RowCount") is nothing then
    count = cint(viewstate("RowCount"))
    end

    count += 1
    for i as iteger = 0 to count
    'ADD row
    next
    viewstate("RowCount") = count

    Karl

    "bruce barker" <> wrote in message
    news:...
    > you have to re-add dynamic controls on postback, so you will need to
    > remember that you added them.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Matthew MacDonald" <> wrote in message
    > news:...
    > > Hi all,
    > > I'm trying to make a web form that will allow the user to continuously

    > add
    > > options to a form by clicking a button.
    > >
    > > Here is my sample code.
    > >
    > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > > System.EventArgs) Handles Button1.Click
    > >
    > > Dim drop As New DropDownList
    > >
    > >
    > >
    > > tblMain.Rows(13).Cells(1).Controls.Add(drop)
    > >
    > > End Sub
    > >
    > > I want this to keep adding new drop down lists to the table whenever the
    > > user clicks the button. What happens, however, is that the page reloads

    > and
    > > only one new control is ever added to the page (or more exactly, the
    > > previous new control is wiped out and a new one is added, thus only ever
    > > having one)
    > >
    > >
    > > Any ideas on this??
    > >
    > > Thanks, Matt
    > >
    > >

    >
    >
    Karl, Aug 24, 2004
    #4
  5. OK, that all makes sence. The problem however is that the controls
    (specificaly dropdownlists) that have been added will probably have user
    selections in them. When I add another one, I want the users selections for
    the first controls to be maintained. I'm sure I could keep track of all of
    this, but there has got to be a better way. Can you push a stack or que
    onto the session or something like that?

    Matt

    "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
    message news:%23N%...
    > Tables don't maintain their state in postback. You can track how often a
    > row has been added in viewstate and add that amount:
    >
    > dim count as integer = 0
    > if not ViewState("RowCount") is nothing then
    > count = cint(viewstate("RowCount"))
    > end
    >
    > count += 1
    > for i as iteger = 0 to count
    > 'ADD row
    > next
    > viewstate("RowCount") = count
    >
    > Karl
    >
    > "bruce barker" <> wrote in message
    > news:...
    > > you have to re-add dynamic controls on postback, so you will need to
    > > remember that you added them.
    > >
    > > -- bruce (sqlwork.com)
    > >
    > >
    > > "Matthew MacDonald" <> wrote in message
    > > news:...
    > > > Hi all,
    > > > I'm trying to make a web form that will allow the user to

    continuously
    > > add
    > > > options to a form by clicking a button.
    > > >
    > > > Here is my sample code.
    > > >
    > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > > > System.EventArgs) Handles Button1.Click
    > > >
    > > > Dim drop As New DropDownList
    > > >
    > > >
    > > >
    > > > tblMain.Rows(13).Cells(1).Controls.Add(drop)
    > > >
    > > > End Sub
    > > >
    > > > I want this to keep adding new drop down lists to the table whenever

    the
    > > > user clicks the button. What happens, however, is that the page

    reloads
    > > and
    > > > only one new control is ever added to the page (or more exactly, the
    > > > previous new control is wiped out and a new one is added, thus only

    ever
    > > > having one)
    > > >
    > > >
    > > > Any ideas on this??
    > > >
    > > > Thanks, Matt
    > > >
    > > >

    > >
    > >

    >
    >
    Matthew MacDonald, Aug 26, 2004
    #5
    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. Dave Horoschak

    Auction website additions

    Dave Horoschak, Mar 6, 2004, in forum: Perl
    Replies:
    0
    Views:
    538
    Dave Horoschak
    Mar 6, 2004
  2. Replies:
    3
    Views:
    376
    Wibble
    May 24, 2005
  3. melledge
    Replies:
    0
    Views:
    361
    melledge
    Oct 4, 2005
  4. melledge
    Replies:
    0
    Views:
    328
    melledge
    Oct 4, 2005
  5. melledge
    Replies:
    0
    Views:
    301
    melledge
    Oct 4, 2005
Loading...

Share This Page