Creating dynamic Text boxes in VB .Net

Discussion in 'ASP .Net Building Controls' started by Coleen, Nov 8, 2004.

  1. Coleen

    Coleen Guest

    Hi All :) (I've posted at dotnet.languates.vb.controls, but not received
    any response since 11/5 - sorry for the doble-post, but I really could use
    some help...)

    I need to create some labels and text boxes dynamically, depending on the
    number input in a previous textbox on the page. What I have is a situation
    where my users receive payments from a client that sometimes consist of
    multiple checks of various amounts, at the same time. This would not pose a
    problem if they received multiple checks on different dates...

    I have an input box for them to enter how many separate checks have been
    received. Now, depending on the number entered in the input box, I need to
    create that many text boxes for them to enter the check number and amount
    for EACH check received. Any suggestions or examples of where I can find out
    how to do this? TIA,

    Coleen
     
    Coleen, Nov 8, 2004
    #1
    1. Advertisements

  2. Hi Coleen,

    What kind of input box are you speaking of?

    The key here is that you need to create the dynamic controls in Page_Init
    or Page_Load. In your example, you are probably checking the value entered
    in a Click event of a button. By then, it's too late to add your controls.


    What you would want to do in this case is check to see if the button on
    your form was the cause of postback. You can do that by checking the Forms
    collection for the existence of that button. Only if the button was used
    to POST will it be part of the Forms collection. Once you've confirmed
    that the button did cause postback, you can once again use the Forms
    collection to determine what was entered in the textbox.

    Using this method, you can do all of your work in Page_Init or Page_Load.
    Hope that helps.

    Jim Cheshire [MSFT]
    MCP+I, MCSE, MCSD, MCDBA
    ASP.NET Developer Support


    This post is provided "AS-IS" with no warranties and confers no rights.

    --------------------
    | From: "Coleen" <>
    | Subject: Creating dynamic Text boxes in VB .Net
    | Date: Mon, 8 Nov 2004 10:56:27 -0800
    | Lines: 19
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: virt50249.virtual.state.nv.us 167.154.50.249
    | Path:
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
    .phx.gbl
    | Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:11630
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | Hi All :) (I've posted at dotnet.languates.vb.controls, but not received
    | any response since 11/5 - sorry for the doble-post, but I really could use
    | some help...)
    |
    | I need to create some labels and text boxes dynamically, depending on the
    | number input in a previous textbox on the page. What I have is a situation
    | where my users receive payments from a client that sometimes consist of
    | multiple checks of various amounts, at the same time. This would not pose
    a
    | problem if they received multiple checks on different dates...
    |
    | I have an input box for them to enter how many separate checks have been
    | received. Now, depending on the number entered in the input box, I need to
    | create that many text boxes for them to enter the check number and amount
    | for EACH check received. Any suggestions or examples of where I can find
    out
    | how to do this? TIA,
    |
    | Coleen
    |
    |
    |
     
    Jim Cheshire [MSFT], Nov 8, 2004
    #2
    1. Advertisements

  3. Coleen

    Coleen Guest

    Actually I'm not doing it on the click of a button. I am doing it on the
    page_load event, on enter. I believe I'm missing a step. Here's my code:

    If txt_num_of_cks.Text <> "" Then
    Select Case ls_num_checks
    Case 1
    Dim lbl_ck_num_1 As New System.Web.UI.WebControls.Label()
    Dim txt_ck_num_1 As New System.Web.UI.WebControls.TextBox()
    Me.Controls.Add(lbl_ck_num_1)
    lbl_ck_num_1.Visible = True
    lbl_ck_num_1.Text = "Enter First Check Number:"
    'More Select Statments but non work...
    End Select
    End If

    I am getting this error: "The Controls collection cannot be modified because
    the control contains code blocks (i.e. <% ... %>). "

    Can you please point me in the right direction? This used to be very simple
    in VB 6, but I am obviously missing a step...



     
    Coleen, Nov 8, 2004
    #3
  4. Coleen,

    You are adding your controls to the page's Controls collection. You
    shouldn't be doing that. Instead, use a placeholder, a literal, a panel,
    etc. and add your controls to its Controls collection.

    Jim Cheshire [MSFT]
    MCP+I, MCSE, MCSD, MCDBA
    ASP.NET Developer Support


    This post is provided "AS-IS" with no warranties and confers no rights.

    --------------------
    | From: "Coleen" <>
    | References: <>
    <>
    | Subject: Re: Creating dynamic Text boxes in VB .Net
    | Date: Mon, 8 Nov 2004 13:18:07 -0800
    | Lines: 106
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: virt50249.virtual.state.nv.us 167.154.50.249
    | Path:
    cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14
    .phx.gbl
    | Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:11632
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | Actually I'm not doing it on the click of a button. I am doing it on the
    | page_load event, on enter. I believe I'm missing a step. Here's my code:
    |
    | If txt_num_of_cks.Text <> "" Then
    | Select Case ls_num_checks
    | Case 1
    | Dim lbl_ck_num_1 As New System.Web.UI.WebControls.Label()
    | Dim txt_ck_num_1 As New System.Web.UI.WebControls.TextBox()
    | Me.Controls.Add(lbl_ck_num_1)
    | lbl_ck_num_1.Visible = True
    | lbl_ck_num_1.Text = "Enter First Check Number:"
    | 'More Select Statments but non work...
    | End Select
    | End If
    |
    | I am getting this error: "The Controls collection cannot be modified
    because
    | the control contains code blocks (i.e. <% ... %>). "
    |
    | Can you please point me in the right direction? This used to be very
    simple
    | in VB 6, but I am obviously missing a step...
    |
    |
    |
    | | > Hi Coleen,
    | >
    | > What kind of input box are you speaking of?
    | >
    | > The key here is that you need to create the dynamic controls in
    Page_Init
    | > or Page_Load. In your example, you are probably checking the value
    | entered
    | > in a Click event of a button. By then, it's too late to add your
    | controls.
    | >
    | >
    | > What you would want to do in this case is check to see if the button on
    | > your form was the cause of postback. You can do that by checking the
    | Forms
    | > collection for the existence of that button. Only if the button was
    used
    | > to POST will it be part of the Forms collection. Once you've confirmed
    | > that the button did cause postback, you can once again use the Forms
    | > collection to determine what was entered in the textbox.
    | >
    | > Using this method, you can do all of your work in Page_Init or
    Page_Load.
    | > Hope that helps.
    | >
    | > Jim Cheshire [MSFT]
    | > MCP+I, MCSE, MCSD, MCDBA
    | > ASP.NET Developer Support
    | >
    | >
    | > This post is provided "AS-IS" with no warranties and confers no rights.
    | >
    | > --------------------
    | > | From: "Coleen" <>
    | > | Subject: Creating dynamic Text boxes in VB .Net
    | > | Date: Mon, 8 Nov 2004 10:56:27 -0800
    | > | Lines: 19
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | NNTP-Posting-Host: virt50249.virtual.state.nv.us 167.154.50.249
    | > | Path:
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
    | > phx.gbl
    | > | Xref: cpmsftngxa10.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11630
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > |
    | > | Hi All :) (I've posted at dotnet.languates.vb.controls, but not
    | received
    | > | any response since 11/5 - sorry for the doble-post, but I really could
    | use
    | > | some help...)
    | > |
    | > | I need to create some labels and text boxes dynamically, depending on
    | the
    | > | number input in a previous textbox on the page. What I have is a
    | situation
    | > | where my users receive payments from a client that sometimes consist
    of
    | > | multiple checks of various amounts, at the same time. This would not
    | pose
    | > a
    | > | problem if they received multiple checks on different dates...
    | > |
    | > | I have an input box for them to enter how many separate checks have
    been
    | > | received. Now, depending on the number entered in the input box, I
    need
    | to
    | > | create that many text boxes for them to enter the check number and
    | amount
    | > | for EACH check received. Any suggestions or examples of where I can
    find
    | > out
    | > | how to do this? TIA,
    | > |
    | > | Coleen
    | > |
    | > |
    | > |
    | >
    |
    |
    |
     
    Jim Cheshire [MSFT], Nov 9, 2004
    #4
  5. Coleen

    Coleen Guest

    Thanks - actually I found exactly what/how I need to do this in an article
    in dotnetjunkies.com: "Building ASP.Net Controls in VB .Net and HTML" The
    example given works, I had to (of course) tweak it a little to fit my needs
    but for anyone seeking the answer, check here:

    http://www.dotnetjunkies.com/HowTo/63C2FC74-EBF4-4284-9306-F987DD1C9580.dcik


    Thanks for the help/response!

    Coleen

     
    Coleen, Nov 9, 2004
    #5
  6. Hi Coleen,

    Unless you need to add table cells to your page, you can do what you need a
    lot easier by just using a container for your controls other than the page.
    The error you were encountering before is caused by the dynamic controls
    getting added outside of the <form> tag. By using a placeholder, panel, or
    some other container other than the page itself, you can avoid that issue
    with no additional code.

    Jim Cheshire [MSFT]
    MCP+I, MCSE, MCSD, MCDBA
    ASP.NET Developer Support


    This post is provided "AS-IS" with no warranties and confers no rights.


    --------------------
    | From: "Coleen" <>
    | References: <>
    <>
    <>
    <>
    | Subject: Re: Creating dynamic Text boxes in VB .Net
    | Date: Tue, 9 Nov 2004 15:08:56 -0800
    | Lines: 179
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: virt29143.virtual.state.nv.us 167.154.29.143
    | Path:
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
    .phx.gbl
    | Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:11640
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | Thanks - actually I found exactly what/how I need to do this in an article
    | in dotnetjunkies.com: "Building ASP.Net Controls in VB .Net and HTML" The
    | example given works, I had to (of course) tweak it a little to fit my
    needs
    | but for anyone seeking the answer, check here:
    |
    |
    http://www.dotnetjunkies.com/HowTo/63C2FC74-EBF4-4284-9306-F987DD1C9580.dcik
    |
    |
    | Thanks for the help/response!
    |
    | Coleen
    |
    | | > Coleen,
    | >
    | > You are adding your controls to the page's Controls collection. You
    | > shouldn't be doing that. Instead, use a placeholder, a literal, a
    panel,
    | > etc. and add your controls to its Controls collection.
    | >
    | > Jim Cheshire [MSFT]
    | > MCP+I, MCSE, MCSD, MCDBA
    | > ASP.NET Developer Support
    | >
    | >
    | > This post is provided "AS-IS" with no warranties and confers no rights.
    | >
    | > --------------------
    | > | From: "Coleen" <>
    | > | References: <>
    | > <>
    | > | Subject: Re: Creating dynamic Text boxes in VB .Net
    | > | Date: Mon, 8 Nov 2004 13:18:07 -0800
    | > | Lines: 106
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | NNTP-Posting-Host: virt50249.virtual.state.nv.us 167.154.50.249
    | > | Path:
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14
    | > phx.gbl
    | > | Xref: cpmsftngxa10.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11632
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > |
    | > | Actually I'm not doing it on the click of a button. I am doing it on
    | the
    | > | page_load event, on enter. I believe I'm missing a step. Here's my
    | code:
    | > |
    | > | If txt_num_of_cks.Text <> "" Then
    | > | Select Case ls_num_checks
    | > | Case 1
    | > | Dim lbl_ck_num_1 As New System.Web.UI.WebControls.Label()
    | > | Dim txt_ck_num_1 As New System.Web.UI.WebControls.TextBox()
    | > | Me.Controls.Add(lbl_ck_num_1)
    | > | lbl_ck_num_1.Visible = True
    | > | lbl_ck_num_1.Text = "Enter First Check Number:"
    | > | 'More Select Statments but non work...
    | > | End Select
    | > | End If
    | > |
    | > | I am getting this error: "The Controls collection cannot be modified
    | > because
    | > | the control contains code blocks (i.e. <% ... %>). "
    | > |
    | > | Can you please point me in the right direction? This used to be very
    | > simple
    | > | in VB 6, but I am obviously missing a step...
    | > |
    | > |
    | > |
    | > | | > | > Hi Coleen,
    | > | >
    | > | > What kind of input box are you speaking of?
    | > | >
    | > | > The key here is that you need to create the dynamic controls in
    | > Page_Init
    | > | > or Page_Load. In your example, you are probably checking the value
    | > | entered
    | > | > in a Click event of a button. By then, it's too late to add your
    | > | controls.
    | > | >
    | > | >
    | > | > What you would want to do in this case is check to see if the button
    | on
    | > | > your form was the cause of postback. You can do that by checking
    the
    | > | Forms
    | > | > collection for the existence of that button. Only if the button was
    | > used
    | > | > to POST will it be part of the Forms collection. Once you've
    | confirmed
    | > | > that the button did cause postback, you can once again use the Forms
    | > | > collection to determine what was entered in the textbox.
    | > | >
    | > | > Using this method, you can do all of your work in Page_Init or
    | > Page_Load.
    | > | > Hope that helps.
    | > | >
    | > | > Jim Cheshire [MSFT]
    | > | > MCP+I, MCSE, MCSD, MCDBA
    | > | > ASP.NET Developer Support
    | > | >
    | > | >
    | > | > This post is provided "AS-IS" with no warranties and confers no
    | rights.
    | > | >
    | > | > --------------------
    | > | > | From: "Coleen" <>
    | > | > | Subject: Creating dynamic Text boxes in VB .Net
    | > | > | Date: Mon, 8 Nov 2004 10:56:27 -0800
    | > | > | Lines: 19
    | > | > | X-Priority: 3
    | > | > | X-MSMail-Priority: Normal
    | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | > | Message-ID: <>
    | > | > | Newsgroups:
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | NNTP-Posting-Host: virt50249.virtual.state.nv.us 167.154.50.249
    | > | > | Path:
    | > | >
    | > |
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
    | > | > phx.gbl
    | > | > | Xref: cpmsftngxa10.phx.gbl
    | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11630
    | > | > | X-Tomcat-NG:
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > |
    | > | > | Hi All :) (I've posted at dotnet.languates.vb.controls, but not
    | > | received
    | > | > | any response since 11/5 - sorry for the doble-post, but I really
    | could
    | > | use
    | > | > | some help...)
    | > | > |
    | > | > | I need to create some labels and text boxes dynamically, depending
    | on
    | > | the
    | > | > | number input in a previous textbox on the page. What I have is a
    | > | situation
    | > | > | where my users receive payments from a client that sometimes
    consist
    | > of
    | > | > | multiple checks of various amounts, at the same time. This would
    not
    | > | pose
    | > | > a
    | > | > | problem if they received multiple checks on different dates...
    | > | > |
    | > | > | I have an input box for them to enter how many separate checks
    have
    | > been
    | > | > | received. Now, depending on the number entered in the input box, I
    | > need
    | > | to
    | > | > | create that many text boxes for them to enter the check number and
    | > | amount
    | > | > | for EACH check received. Any suggestions or examples of where I
    can
    | > find
    | > | > out
    | > | > | how to do this? TIA,
    | > | > |
    | > | > | Coleen
    | > | > |
    | > | > |
    | > | > |
    | > | >
    | > |
    | > |
    | > |
    | >
    |
    |
    |
     
    Jim Cheshire [MSFT], Nov 9, 2004
    #6
  7. Coleen

    Coleen Guest

    I may have to do that, because the dropdownlistbox SelectedIndexChanged
    event is not being triggered with the ddl in the asp table. I'm not a
    "brand" newbie to .net, but I am new enough not to quite understand what you
    mean by adding a container. The thing is that I want the labels and text
    boxes to appear and align depending on what type of payment is selected in
    the ddl. I need to populate a total of seven "rows" for each type to get
    the proper data. I though the easiest way to do this and get it all to
    align properly would be to insert all the dropdowns, labels and textboxes
    inside an aspx table...any other suggestions/examples you can provide are
    greatly appreciated!

    TIA

    Coleen


     
    Coleen, Nov 10, 2004
    #7
  8. Coleen,

    A table is fine. The thing is that you need to add your dynamic controls
    to a container other than the page. In other words, suppose you were
    adding them to a Panel control called pnlControls. You would just add the
    controls to the Controls collection of pnlControls.

    pnlControls.Controls.Add(myControl)

    That will prevent the controls from getting added outside of the <form> tag
    and causing a problem.

    Jim Cheshire [MSFT]
    MCP+I, MCSE, MCSD, MCDBA
    ASP.NET Developer Support


    This post is provided "AS-IS" with no warranties and confers no rights.

    --------------------
    | From: "Coleen" <>
    | References: <>
    <>
    <>
    <>
    <>
    <>
    | Subject: Re: Creating dynamic Text boxes in VB .Net
    | Date: Wed, 10 Nov 2004 14:50:46 -0800
    | Lines: 273
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | Message-ID: <O#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: virt42139.virtual.state.nv.us 167.154.42.139
    | Path:
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15
    .phx.gbl
    | Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:11652
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | I may have to do that, because the dropdownlistbox SelectedIndexChanged
    | event is not being triggered with the ddl in the asp table. I'm not a
    | "brand" newbie to .net, but I am new enough not to quite understand what
    you
    | mean by adding a container. The thing is that I want the labels and text
    | boxes to appear and align depending on what type of payment is selected in
    | the ddl. I need to populate a total of seven "rows" for each type to get
    | the proper data. I though the easiest way to do this and get it all to
    | align properly would be to insert all the dropdowns, labels and textboxes
    | inside an aspx table...any other suggestions/examples you can provide are
    | greatly appreciated!
    |
    | TIA
    |
    | Coleen
    |
    |
    | | > Hi Coleen,
    | >
    | > Unless you need to add table cells to your page, you can do what you
    need
    | a
    | > lot easier by just using a container for your controls other than the
    | page.
    | > The error you were encountering before is caused by the dynamic
    controls
    | > getting added outside of the <form> tag. By using a placeholder, panel,
    | or
    | > some other container other than the page itself, you can avoid that
    issue
    | > with no additional code.
    | >
    | > Jim Cheshire [MSFT]
    | > MCP+I, MCSE, MCSD, MCDBA
    | > ASP.NET Developer Support
    | >
    | >
    | > This post is provided "AS-IS" with no warranties and confers no rights.
    | >
    | >
    | > --------------------
    | > | From: "Coleen" <>
    | > | References: <>
    | > <>
    | > <>
    | > <>
    | > | Subject: Re: Creating dynamic Text boxes in VB .Net
    | > | Date: Tue, 9 Nov 2004 15:08:56 -0800
    | > | Lines: 179
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | NNTP-Posting-Host: virt29143.virtual.state.nv.us 167.154.29.143
    | > | Path:
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
    | > phx.gbl
    | > | Xref: cpmsftngxa10.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11640
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > |
    | > | Thanks - actually I found exactly what/how I need to do this in an
    | article
    | > | in dotnetjunkies.com: "Building ASP.Net Controls in VB .Net and HTML"
    | The
    | > | example given works, I had to (of course) tweak it a little to fit my
    | > needs
    | > | but for anyone seeking the answer, check here:
    | > |
    | > |
    | >
    |
    http://www.dotnetjunkies.com/HowTo/63C2FC74-EBF4-4284-9306-F987DD1C9580.dcik
    | > |
    | > |
    | > | Thanks for the help/response!
    | > |
    | > | Coleen
    | > |
    | > | | > | > Coleen,
    | > | >
    | > | > You are adding your controls to the page's Controls collection. You
    | > | > shouldn't be doing that. Instead, use a placeholder, a literal, a
    | > panel,
    | > | > etc. and add your controls to its Controls collection.
    | > | >
    | > | > Jim Cheshire [MSFT]
    | > | > MCP+I, MCSE, MCSD, MCDBA
    | > | > ASP.NET Developer Support
    | > | >
    | > | >
    | > | > This post is provided "AS-IS" with no warranties and confers no
    | rights.
    | > | >
    | > | > --------------------
    | > | > | From: "Coleen" <>
    | > | > | References: <>
    | > | > <>
    | > | > | Subject: Re: Creating dynamic Text boxes in VB .Net
    | > | > | Date: Mon, 8 Nov 2004 13:18:07 -0800
    | > | > | Lines: 106
    | > | > | X-Priority: 3
    | > | > | X-MSMail-Priority: Normal
    | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | > | Message-ID: <>
    | > | > | Newsgroups:
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | NNTP-Posting-Host: virt50249.virtual.state.nv.us 167.154.50.249
    | > | > | Path:
    | > | >
    | > |
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14
    | > | > phx.gbl
    | > | > | Xref: cpmsftngxa10.phx.gbl
    | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11632
    | > | > | X-Tomcat-NG:
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > |
    | > | > | Actually I'm not doing it on the click of a button. I am doing it
    | on
    | > | the
    | > | > | page_load event, on enter. I believe I'm missing a step. Here's
    my
    | > | code:
    | > | > |
    | > | > | If txt_num_of_cks.Text <> "" Then
    | > | > | Select Case ls_num_checks
    | > | > | Case 1
    | > | > | Dim lbl_ck_num_1 As New System.Web.UI.WebControls.Label()
    | > | > | Dim txt_ck_num_1 As New System.Web.UI.WebControls.TextBox()
    | > | > | Me.Controls.Add(lbl_ck_num_1)
    | > | > | lbl_ck_num_1.Visible = True
    | > | > | lbl_ck_num_1.Text = "Enter First Check Number:"
    | > | > | 'More Select Statments but non work...
    | > | > | End Select
    | > | > | End If
    | > | > |
    | > | > | I am getting this error: "The Controls collection cannot be
    modified
    | > | > because
    | > | > | the control contains code blocks (i.e. <% ... %>). "
    | > | > |
    | > | > | Can you please point me in the right direction? This used to be
    | very
    | > | > simple
    | > | > | in VB 6, but I am obviously missing a step...
    | > | > |
    | > | > |
    | > | > |
    | message
    | > | > | | > | > | > Hi Coleen,
    | > | > | >
    | > | > | > What kind of input box are you speaking of?
    | > | > | >
    | > | > | > The key here is that you need to create the dynamic controls in
    | > | > Page_Init
    | > | > | > or Page_Load. In your example, you are probably checking the
    | value
    | > | > | entered
    | > | > | > in a Click event of a button. By then, it's too late to add
    your
    | > | > | controls.
    | > | > | >
    | > | > | >
    | > | > | > What you would want to do in this case is check to see if the
    | button
    | > | on
    | > | > | > your form was the cause of postback. You can do that by
    checking
    | > the
    | > | > | Forms
    | > | > | > collection for the existence of that button. Only if the button
    | was
    | > | > used
    | > | > | > to POST will it be part of the Forms collection. Once you've
    | > | confirmed
    | > | > | > that the button did cause postback, you can once again use the
    | Forms
    | > | > | > collection to determine what was entered in the textbox.
    | > | > | >
    | > | > | > Using this method, you can do all of your work in Page_Init or
    | > | > Page_Load.
    | > | > | > Hope that helps.
    | > | > | >
    | > | > | > Jim Cheshire [MSFT]
    | > | > | > MCP+I, MCSE, MCSD, MCDBA
    | > | > | > ASP.NET Developer Support
    | > | > | >
    | > | > | >
    | > | > | > This post is provided "AS-IS" with no warranties and confers no
    | > | rights.
    | > | > | >
    | > | > | > --------------------
    | > | > | > | From: "Coleen" <>
    | > | > | > | Subject: Creating dynamic Text boxes in VB .Net
    | > | > | > | Date: Mon, 8 Nov 2004 10:56:27 -0800
    | > | > | > | Lines: 19
    | > | > | > | X-Priority: 3
    | > | > | > | X-MSMail-Priority: Normal
    | > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | > | > | Message-ID: <>
    | > | > | > | Newsgroups:
    | > | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | > | NNTP-Posting-Host: virt50249.virtual.state.nv.us
    167.154.50.249
    | > | > | > | Path:
    | > | > | >
    | > | > |
    | > | >
    | > |
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
    | > | > | > phx.gbl
    | > | > | > | Xref: cpmsftngxa10.phx.gbl
    | > | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11630
    | > | > | > | X-Tomcat-NG:
    | > | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | > |
    | > | > | > | Hi All :) (I've posted at dotnet.languates.vb.controls, but
    not
    | > | > | received
    | > | > | > | any response since 11/5 - sorry for the doble-post, but I
    really
    | > | could
    | > | > | use
    | > | > | > | some help...)
    | > | > | > |
    | > | > | > | I need to create some labels and text boxes dynamically,
    | depending
    | > | on
    | > | > | the
    | > | > | > | number input in a previous textbox on the page. What I have
    is a
    | > | > | situation
    | > | > | > | where my users receive payments from a client that sometimes
    | > consist
    | > | > of
    | > | > | > | multiple checks of various amounts, at the same time. This
    would
    | > not
    | > | > | pose
    | > | > | > a
    | > | > | > | problem if they received multiple checks on different dates...
    | > | > | > |
    | > | > | > | I have an input box for them to enter how many separate checks
    | > have
    | > | > been
    | > | > | > | received. Now, depending on the number entered in the input
    box,
    | I
    | > | > need
    | > | > | to
    | > | > | > | create that many text boxes for them to enter the check number
    | and
    | > | > | amount
    | > | > | > | for EACH check received. Any suggestions or examples of where
    I
    | > can
    | > | > find
    | > | > | > out
    | > | > | > | how to do this? TIA,
    | > | > | > |
    | > | > | > | Coleen
    | > | > | > |
    | > | > | > |
    | > | > | > |
    | > | > | >
    | > | > |
    | > | > |
    | > | > |
    | > | >
    | > |
    | > |
    | > |
    | >
    |
    |
    |
     
    Jim Cheshire [MSFT], Nov 10, 2004
    #8
  9. Coleen

    Coleen Guest

    I guess I'm a little confused. Does the table get placed inside the
    container? I've never used containers before, so I honestly don't have a
    clue where to start coding..."just add the controls to the Controls
    collection of pnlControls" is the control created and then the entire table
    placed inside, or is the container placed inside the table?


     
    Coleen, Nov 11, 2004
    #9
  10. Coleen,

    It doesn't matter. The panel is added during design-time and you can put
    it anywhere. It's simply a placeholder for the dynamic controls that will
    be added later.

    Jim Cheshire [MSFT]
    MCP+I, MCSE, MCSD, MCDBA
    ASP.NET Developer Support


    This post is provided "AS-IS" with no warranties and confers no rights.

    --------------------
    | From: "Coleen" <>
    | References: <>
    <>
    <>
    <>
    <>
    <>
    <O#>
    <>
    | Subject: Re: Creating dynamic Text boxes in VB .Net
    | Date: Wed, 10 Nov 2004 16:21:35 -0800
    | Lines: 378
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | Message-ID: <OsZo#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: virt42139.virtual.state.nv.us 167.154.42.139
    | Path:
    cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09
    ..phx.gbl
    | Xref: cpmsftngxa10.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:11654
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | I guess I'm a little confused. Does the table get placed inside the
    | container? I've never used containers before, so I honestly don't have a
    | clue where to start coding..."just add the controls to the Controls
    | collection of pnlControls" is the control created and then the entire
    table
    | placed inside, or is the container placed inside the table?
    |
    |
    | | > Coleen,
    | >
    | > A table is fine. The thing is that you need to add your dynamic
    controls
    | > to a container other than the page. In other words, suppose you were
    | > adding them to a Panel control called pnlControls. You would just add
    the
    | > controls to the Controls collection of pnlControls.
    | >
    | > pnlControls.Controls.Add(myControl)
    | >
    | > That will prevent the controls from getting added outside of the <form>
    | tag
    | > and causing a problem.
    | >
    | > Jim Cheshire [MSFT]
    | > MCP+I, MCSE, MCSD, MCDBA
    | > ASP.NET Developer Support
    | >
    | >
    | > This post is provided "AS-IS" with no warranties and confers no rights.
    | >
    | > --------------------
    | > | From: "Coleen" <>
    | > | References: <>
    | > <>
    | > <>
    | > <>
    | > <>
    | > <>
    | > | Subject: Re: Creating dynamic Text boxes in VB .Net
    | > | Date: Wed, 10 Nov 2004 14:50:46 -0800
    | > | Lines: 273
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | Message-ID: <O#>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | NNTP-Posting-Host: virt42139.virtual.state.nv.us 167.154.42.139
    | > | Path:
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15
    | > phx.gbl
    | > | Xref: cpmsftngxa10.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11652
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > |
    | > | I may have to do that, because the dropdownlistbox
    SelectedIndexChanged
    | > | event is not being triggered with the ddl in the asp table. I'm not a
    | > | "brand" newbie to .net, but I am new enough not to quite understand
    what
    | > you
    | > | mean by adding a container. The thing is that I want the labels and
    | text
    | > | boxes to appear and align depending on what type of payment is
    selected
    | in
    | > | the ddl. I need to populate a total of seven "rows" for each type to
    | get
    | > | the proper data. I though the easiest way to do this and get it all
    to
    | > | align properly would be to insert all the dropdowns, labels and
    | textboxes
    | > | inside an aspx table...any other suggestions/examples you can provide
    | are
    | > | greatly appreciated!
    | > |
    | > | TIA
    | > |
    | > | Coleen
    | > |
    | > |
    | > | | > | > Hi Coleen,
    | > | >
    | > | > Unless you need to add table cells to your page, you can do what you
    | > need
    | > | a
    | > | > lot easier by just using a container for your controls other than
    the
    | > | page.
    | > | > The error you were encountering before is caused by the dynamic
    | > controls
    | > | > getting added outside of the <form> tag. By using a placeholder,
    | panel,
    | > | or
    | > | > some other container other than the page itself, you can avoid that
    | > issue
    | > | > with no additional code.
    | > | >
    | > | > Jim Cheshire [MSFT]
    | > | > MCP+I, MCSE, MCSD, MCDBA
    | > | > ASP.NET Developer Support
    | > | >
    | > | >
    | > | > This post is provided "AS-IS" with no warranties and confers no
    | rights.
    | > | >
    | > | >
    | > | > --------------------
    | > | > | From: "Coleen" <>
    | > | > | References: <>
    | > | > <>
    | > | > <>
    | > | > <>
    | > | > | Subject: Re: Creating dynamic Text boxes in VB .Net
    | > | > | Date: Tue, 9 Nov 2004 15:08:56 -0800
    | > | > | Lines: 179
    | > | > | X-Priority: 3
    | > | > | X-MSMail-Priority: Normal
    | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | > | Message-ID: <>
    | > | > | Newsgroups:
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | NNTP-Posting-Host: virt29143.virtual.state.nv.us 167.154.29.143
    | > | > | Path:
    | > | >
    | > |
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
    | > | > phx.gbl
    | > | > | Xref: cpmsftngxa10.phx.gbl
    | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11640
    | > | > | X-Tomcat-NG:
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > |
    | > | > | Thanks - actually I found exactly what/how I need to do this in an
    | > | article
    | > | > | in dotnetjunkies.com: "Building ASP.Net Controls in VB .Net and
    | HTML"
    | > | The
    | > | > | example given works, I had to (of course) tweak it a little to fit
    | my
    | > | > needs
    | > | > | but for anyone seeking the answer, check here:
    | > | > |
    | > | > |
    | > | >
    | > |
    | >
    |
    http://www.dotnetjunkies.com/HowTo/63C2FC74-EBF4-4284-9306-F987DD1C9580.dcik
    | > | > |
    | > | > |
    | > | > | Thanks for the help/response!
    | > | > |
    | > | > | Coleen
    | > | > |
    | message
    | > | > | | > | > | > Coleen,
    | > | > | >
    | > | > | > You are adding your controls to the page's Controls collection.
    | You
    | > | > | > shouldn't be doing that. Instead, use a placeholder, a
    literal, a
    | > | > panel,
    | > | > | > etc. and add your controls to its Controls collection.
    | > | > | >
    | > | > | > Jim Cheshire [MSFT]
    | > | > | > MCP+I, MCSE, MCSD, MCDBA
    | > | > | > ASP.NET Developer Support
    | > | > | >
    | > | > | >
    | > | > | > This post is provided "AS-IS" with no warranties and confers no
    | > | rights.
    | > | > | >
    | > | > | > --------------------
    | > | > | > | From: "Coleen" <>
    | > | > | > | References: <>
    | > | > | > <>
    | > | > | > | Subject: Re: Creating dynamic Text boxes in VB .Net
    | > | > | > | Date: Mon, 8 Nov 2004 13:18:07 -0800
    | > | > | > | Lines: 106
    | > | > | > | X-Priority: 3
    | > | > | > | X-MSMail-Priority: Normal
    | > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | > | > | Message-ID: <>
    | > | > | > | Newsgroups:
    | > | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | > | NNTP-Posting-Host: virt50249.virtual.state.nv.us
    167.154.50.249
    | > | > | > | Path:
    | > | > | >
    | > | > |
    | > | >
    | > |
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14
    | > | > | > phx.gbl
    | > | > | > | Xref: cpmsftngxa10.phx.gbl
    | > | > | > microsoft.public.dotnet.framework.aspnet.buildingcontrols:11632
    | > | > | > | X-Tomcat-NG:
    | > | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | > |
    | > | > | > | Actually I'm not doing it on the click of a button. I am
    doing
    | it
    | > | on
    | > | > | the
    | > | > | > | page_load event, on enter. I believe I'm missing a step.
    | Here's
    | > my
    | > | > | code:
    | > | > | > |
    | > | > | > | If txt_num_of_cks.Text <> "" Then
    | > | > | > | Select Case ls_num_checks
    | > | > | > | Case 1
    | > | > | > | Dim lbl_ck_num_1 As New System.Web.UI.WebControls.Label()
    | > | > | > | Dim txt_ck_num_1 As New System.Web.UI.WebControls.TextBox()
    | > | > | > | Me.Controls.Add(lbl_ck_num_1)
    | > | > | > | lbl_ck_num_1.Visible = True
    | > | > | > | lbl_ck_num_1.Text = "Enter First Check Number:"
    | > | > | > | 'More Select Statments but non work...
    | > | > | > | End Select
    | > | > | > | End If
    | > | > | > |
    | > | > | > | I am getting this error: "The Controls collection cannot be
    | > modified
    | > | > | > because
    | > | > | > | the control contains code blocks (i.e. <% ... %>). "
    | > | > | > |
    | > | > | > | Can you please point me in the right direction? This used to
    be
    | > | very
    | > | > | > simple
    | > | > | > | in VB 6, but I am obviously missing a step...
    | > | > | > |
    | > | > | > |
    | > | > | > |
    | > | message
    | > | > | > | | > | > | > | > Hi Coleen,
    | > | > | > | >
    | > | > | > | > What kind of input box are you speaking of?
    | > | > | > | >
    | > | > | > | > The key here is that you need to create the dynamic controls
    | in
    | > | > | > Page_Init
    | > | > | > | > or Page_Load. In your example, you are probably checking
    the
    | > | value
    | > | > | > | entered
    | > | > | > | > in a Click event of a button. By then, it's too late to add
    | > your
    | > | > | > | controls.
    | > | > | > | >
    | > | > | > | >
    | > | > | > | > What you would want to do in this case is check to see if
    the
    | > | button
    | > | > | on
    | > | > | > | > your form was the cause of postback. You can do that by
    | > checking
    | > | > the
    | > | > | > | Forms
    | > | > | > | > collection for the existence of that button. Only if the
    | button
    | > | was
    | > | > | > used
    | > | > | > | > to POST will it be part of the Forms collection. Once
    you've
    | > | > | confirmed
    | > | > | > | > that the button did cause postback, you can once again use
    the
    | > | Forms
    | > | > | > | > collection to determine what was entered in the textbox.
    | > | > | > | >
    | > | > | > | > Using this method, you can do all of your work in Page_Init
    or
    | > | > | > Page_Load.
    | > | > | > | > Hope that helps.
    | > | > | > | >
    | > | > | > | > Jim Cheshire [MSFT]
    | > | > | > | > MCP+I, MCSE, MCSD, MCDBA
    | > | > | > | > ASP.NET Developer Support
    | > | > | > | >
    | > | > | > | >
    | > | > | > | > This post is provided "AS-IS" with no warranties and confers
    | no
    | > | > | rights.
    | > | > | > | >
    | > | > | > | > --------------------
    | > | > | > | > | From: "Coleen" <>
    | > | > | > | > | Subject: Creating dynamic Text boxes in VB .Net
    | > | > | > | > | Date: Mon, 8 Nov 2004 10:56:27 -0800
    | > | > | > | > | Lines: 19
    | > | > | > | > | X-Priority: 3
    | > | > | > | > | X-MSMail-Priority: Normal
    | > | > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
    | > | > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
    | > | > | > | > | Message-ID: <>
    | > | > | > | > | Newsgroups:
    | > | > | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | > | > | NNTP-Posting-Host: virt50249.virtual.state.nv.us
    | > 167.154.50.249
    | > | > | > | > | Path:
    | > | > | > | >
    | > | > | > |
    | > | > | >
    | > | > |
    | > | >
    | > |
    | >
    |
    cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
    | > | > | > | > phx.gbl
    | > | > | > | > | Xref: cpmsftngxa10.phx.gbl
    | > | > | > | >
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols:11630
    | > | > | > | > | X-Tomcat-NG:
    | > | > | microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | > | > | > | > |
    | > | > | > | > | Hi All :) (I've posted at dotnet.languates.vb.controls,
    but
    | > not
    | > | > | > | received
    | > | > | > | > | any response since 11/5 - sorry for the doble-post, but I
    | > really
    | > | > | could
    | > | > | > | use
    | > | > | > | > | some help...)
    | > | > | > | > |
    | > | > | > | > | I need to create some labels and text boxes dynamically,
    | > | depending
    | > | > | on
    | > | > | > | the
    | > | > | > | > | number input in a previous textbox on the page. What I
    have
    | > is a
    | > | > | > | situation
    | > | > | > | > | where my users receive payments from a client that
    sometimes
    | > | > consist
    | > | > | > of
    | > | > | > | > | multiple checks of various amounts, at the same time. This
    | > would
    | > | > not
    | > | > | > | pose
    | > | > | > | > a
    | > | > | > | > | problem if they received multiple checks on different
    | dates...
    | > | > | > | > |
    | > | > | > | > | I have an input box for them to enter how many separate
    | checks
    | > | > have
    | > | > | > been
    | > | > | > | > | received. Now, depending on the number entered in the
    input
    | > box,
    | > | I
    | > | > | > need
    | > | > | > | to
    | > | > | > | > | create that many text boxes for them to enter the check
    | number
    | > | and
    | > | > | > | amount
    | > | > | > | > | for EACH check received. Any suggestions or examples of
    | where
    | > I
    | > | > can
    | > | > | > find
    | > | > | > | > out
    | > | > | > | > | how to do this? TIA,
    | > | > | > | > |
    | > | > | > | > | Coleen
    | > | > | > | > |
    | > | > | > | > |
    | > | > | > | > |
    | > | > | > | >
    | > | > | > |
    | > | > | > |
    | > | > | > |
    | > | > | >
    | > | > |
    | > | > |
    | > | > |
    | > | >
    | > |
    | > |
    | > |
    | >
    |
    |
    |
     
    Jim Cheshire [MSFT], Nov 11, 2004
    #10
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.