Adding textboxes dynamically

Discussion in 'ASP .Net' started by =?Utf-8?B?QWxleCBEZW50b24=?=, Jun 2, 2006.

  1. Okay, here's my problem:

    I need to populate different fields in an HTML table with TextBoxes. For
    example, if I had 3 columns "Name", "Address", and "City"; I need to have a
    TextBox in all of the Address fields. This is basically the code that I used.

    <script language="VB" runat="server">
    Sub Page_Load(Sender As Object, E As EventArgs)
    Label1.Text &= "<td align=left><input type=""text"" id=""txt"
    & _
    Database.ReadField("ID") & _
    """ runat=server value=""" & _
    Database.ReadField("Address") & """></td>"
    End Sub

    Sub Update_Click(Sender As Object, E As EventArgs)
    Dim dba As DatabaseDLL = New DatabaseDLL
    dba.LoadDB_SQL(Server.MapPath("address.mdb"), False, sql)

    Do While Not dba.EOF
    strRead = Request.Form("txt" & dba.ReadField("ID"))
    If strRead <> "" Then
    dba.EditField("JobCost", strRead)
    dba.Update()
    End If

    dba.MoveNext()
    Loop

    dba.CloseDB()
    End Sub
    </script>

    <form runat="server">

    <asp:label id="Label1" runat="server">
    Edit Subtotals:<br><br>
    <a href="view_all_estimate.aspx">Back to Standard View</a><br><br>
    </asp:label>

    <input type="submit" runat="server" id="cmdSubmit"
    onServerClick="Update_Click" value="Update Material Costs">
    </form>


    But when I press Submit, it obviously does not pick up those TextBoxes that
    I added at runtime. How am I supposed to do this?
     
    =?Utf-8?B?QWxleCBEZW50b24=?=, Jun 2, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?QWxleCBEZW50b24=?=

    Mike Lowery Guest

    So you're creating a table using the text of a Label object? I don't think
    that's supported...

    Look at using Controls.Add.LiteralControl. You should add the table to your
    form this way, or even create a table object first and add that.

    Dynamically added controls are a PIA however--you have to recreate them on
    postback or ASP.Net won't see them. This can get confusing/complicated quickly.

    "Alex Denton" <Alex > wrote in message
    news:...
    > Okay, here's my problem:
    >
    > I need to populate different fields in an HTML table with TextBoxes. For
    > example, if I had 3 columns "Name", "Address", and "City"; I need to have a
    > TextBox in all of the Address fields. This is basically the code that I used.
    >
    > <script language="VB" runat="server">
    > Sub Page_Load(Sender As Object, E As EventArgs)
    > Label1.Text &= "<td align=left><input type=""text"" id=""txt"
    > & _
    > Database.ReadField("ID") & _
    > """ runat=server value=""" & _
    > Database.ReadField("Address") & """></td>"
    > End Sub
    >
    > Sub Update_Click(Sender As Object, E As EventArgs)
    > Dim dba As DatabaseDLL = New DatabaseDLL
    > dba.LoadDB_SQL(Server.MapPath("address.mdb"), False, sql)
    >
    > Do While Not dba.EOF
    > strRead = Request.Form("txt" & dba.ReadField("ID"))
    > If strRead <> "" Then
    > dba.EditField("JobCost", strRead)
    > dba.Update()
    > End If
    >
    > dba.MoveNext()
    > Loop
    >
    > dba.CloseDB()
    > End Sub
    > </script>
    >
    > <form runat="server">
    >
    > <asp:label id="Label1" runat="server">
    > Edit Subtotals:<br><br>
    > <a href="view_all_estimate.aspx">Back to Standard View</a><br><br>
    > </asp:label>
    >
    > <input type="submit" runat="server" id="cmdSubmit"
    > onServerClick="Update_Click" value="Update Material Costs">
    > </form>
    >
    >
    > But when I press Submit, it obviously does not pick up those TextBoxes that
    > I added at runtime. How am I supposed to do this?
     
    Mike Lowery, Jun 2, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?QWxleCBEZW50b24=?=

    Guest

    Mike Lowery wrote:
    > So you're creating a table using the text of a Label object? I don't think
    > that's supported...
    >

    Heck yeah its supported. Its a horrible way of doing things, but I've
    built an entire navigable calendar inside the text property of a label.

    But yes, literals are the way to go here.

    Tex
     
    , Jun 2, 2006
    #3
  4. Can you explain to me how I would recreate them on postback while maintaining
    their values?

    "" wrote:

    >
    > Mike Lowery wrote:
    > > So you're creating a table using the text of a Label object? I don't think
    > > that's supported...
    > >

    > Heck yeah its supported. Its a horrible way of doing things, but I've
    > built an entire navigable calendar inside the text property of a label.
    >
    > But yes, literals are the way to go here.
    >
    > Tex
    >
    >
     
    =?Utf-8?B?QWxleCBEZW50b24=?=, Jun 2, 2006
    #4
  5. =?Utf-8?B?QWxleCBEZW50b24=?=

    Mike Lowery Guest

    I should have said "officially supported" in my earlier post.

    See this article:
    http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

    "Alex Denton" <Alex > wrote in message
    news:...
    > Can you explain to me how I would recreate them on postback while maintaining
    > their values?
    >
    > "" wrote:
    >
    >>
    >> Mike Lowery wrote:
    >> > So you're creating a table using the text of a Label object? I don't think
    >> > that's supported...
    >> >

    >> Heck yeah its supported. Its a horrible way of doing things, but I've
    >> built an entire navigable calendar inside the text property of a label.
    >>
    >> But yes, literals are the way to go here.
    >>
    >> Tex
    >>
    >>
     
    Mike Lowery, Jun 5, 2006
    #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. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 1, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    507
    Sam Vanderstraeten
    Oct 1, 2003
  2. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,187
    Sam Vanderstraeten
    Oct 2, 2003
  3. Andreas Klemt
    Replies:
    0
    Views:
    846
    Andreas Klemt
    Feb 1, 2004
  4. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 1, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    231
    Sam Vanderstraeten
    Oct 1, 2003
  5. Sam Vanderstraeten

    Adding textboxes for filtering in DataGrid header

    Sam Vanderstraeten, Oct 2, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    160
    Sam Vanderstraeten
    Oct 2, 2003
Loading...

Share This Page