Values from dynamic controls
Values from dynamic controls
Values from dynamic controls
Values from dynamic controls
Values from dynamic controls
Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls
Values from dynamic controls Values from dynamic controls
Values from dynamic controls
Go Back  Xtreme Visual Basic Talk > > > Values from dynamic controls


Reply
 
Thread Tools Display Modes
  #1  
Old 09-07-2006, 06:16 AM
rosmiq rosmiq is offline
Regular
 
Join Date: Nov 2005
Posts: 71
Default Values from dynamic controls


Hi

does anybody know how to read values from dynamically created controls, i.e. textboxes and tables?

I have created textboxes dynamically and put them into a table. i.e:
The number of rows and textboxes depends on how many items from a checkboxlist is selected.

Code:
    Dim txt As New WebControls.TextBox
                txt.Width = Unit.Point(25)

                cell2.Controls.Add(txt)

This textbox is for the user to input a quantity amount and then I need this value to be stored when the user clicks on another button.

When I read the table it doesn't find anything, the tblQty.rows.count = 0 and it should be 3.

Can anybody please help?

Thanks,
rosmiq

Last edited by rosmiq; 09-07-2006 at 06:53 AM.
Reply With Quote
  #2  
Old 09-07-2006, 08:19 AM
wayneph's Avatar
waynephValues from dynamic controls wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

In the Page_Init event you need to recreate the controls. Otherwise the part of the page that repopulates them, doesn't know they exist. Here is a really good article that should get you on your way to fixing it: http://aspnet.4guysfromrolla.com/articles/092904-1.aspx
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 09-07-2006, 09:40 AM
rosmiq rosmiq is offline
Regular
 
Join Date: Nov 2005
Posts: 71
Default

Thank you very much for your response, that article is great help. But i have just one question about this..

The controls on my page are mostly dropdownlists, which basically filter a database to the users' requirements. The last one they filter down to dynamically creates a checkboxlist, this is dependant on how many items there are for that particular record, that is why i did this dynamically. Once the checkboxes are ticked, i then dynamically create a table with textboxes so they can then input some values.

Which part do I need to put in the page_init? They all depend on each other.
Reply With Quote
  #4  
Old 09-07-2006, 11:30 AM
wayneph's Avatar
waynephValues from dynamic controls wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

If the Dropdown Lists and CheckBox lists are on the page (not added later) then they don't need to be there. What you'll need to do is either store in a session what table items you create, or use the Checkbox list to determine what needs to be recreated.

You shouldn't have to worry about the things that are "always there".
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #5  
Old 09-12-2006, 05:22 AM
rosmiq rosmiq is offline
Regular
 
Join Date: Nov 2005
Posts: 71
Default

Hi thanks for your reply... would it be possible you can give me an example, i'm a bit lost..
Reply With Quote
  #6  
Old 09-12-2006, 08:33 AM
wayneph's Avatar
waynephValues from dynamic controls wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Other than the samples in the 3 articles, I don't have time right now to make one. There should be more than enough there to explain what's going on.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #7  
Old 09-13-2006, 09:44 AM
rosmiq rosmiq is offline
Regular
 
Join Date: Nov 2005
Posts: 71
Default

Quote:
Originally Posted by wayneph
Other than the samples in the 3 articles, I don't have time right now to make one. There should be more than enough there to explain what's going on.
Hi, please see my code:

Code:
  Protected WithEvents txt As New WebControls.TextBox
    Protected WithEvents tblQty As New System.Web.UI.WebControls.Table
Then in my Page_init code i have:
Code:
 Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
       
        txt = New TextBox
        txt.ID = "txt"

        Panel3.Controls.Add(txt)

       
        row = New TableRow
        cell = New TableCell
        cell2 = New TableCell

        tblQty = New Table
        tblQty.ID = "tblQty"
        row.Cells.Add(cell)
        row.Cells.Add(cell2)
        tblQty.Rows.Add(row)

        Panel2.Controls.Add(tblQty)

        InitializeComponent()
    End Sub
In my page_load i have:
Code:
If Not Page.IsPostBack Then
            'Dim txt As New TextBox
            txt.ID = "txt"
            Panel3.Controls.Add(txt)


            '  control()
            ' CreateControl()
            txt.Visible = False
Then I have a checkboxlist which is also created dynamically and depending on how many items are ticked (again there could be an unlimited amount of items in this checkboxlist) a text box is created for user to input a quantity amount.

Code:
Private Sub cbEquip_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEquip.SelectedIndexChanged

        btnSubQty.Visible = True

        If cbEquip.Items(0).Selected Then
            txt.Visible = True
        End If


        Try

            Dim i As Integer
            Dim count As String = cbEquip.Items.Count - 1
            For i = 1 To count
                Dim text As String = cbEquip.Items(i).Text
                If cbEquip.Items(i).Selected Then

                    Dim break As String = text
                    row = New TableRow
                    cell = New TableCell
                    cell2 = New TableCell

                    txt.Visible = True
                    txt = New TextBox
                    txt.ID = "txt" & i
                    Panel3.Controls.Add(txt)

                    cell.Text = break
                    row.Cells.Add(cell)
                    row.Cells.Add(cell2)

                    tblQty.Rows.Add(row)
                    Panel2.Controls.Add(tblQty)

                End If
            Next

        Catch ex As Exception
            Console.WriteLine(ex.Message)

        End Try

    End Sub
Then I also have a sub for txt_textchanged.. as below

Code:
Private Sub txt_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt.TextChanged

        Dim txtBoxSender As TextBox
        Dim strTextBoxID As String

        txtBoxSender = CType(sender, TextBox)
        strTextBoxID = txtBoxSender.ID

        Dim i As Integer
        Dim count As String = cbEquip.Items.Count - 1
        For i = 0 To count
            Dim text As String = cbEquip.Items(i).Text
            If cbEquip.Items(i).Selected Then

                cell2.Text = txtBoxSender.Text

                row.Cells.Add(cell2)
                tblQty.Rows.Add(row)

            End If
        Next



    End Sub
So far with the code above when I click on a checkbox item a text box appears, when i click on another checkbox item another textbox appears and so on, but when I type values in these text boxes I'm only getting the value of the first text box, i.e..

Code:
Protected WithEvents txt As New WebControls.TextBox
I don't know how many text boxes will be created and I don't want to have to declare them each, I could be declaring up to 50, is this what i have to do?

I'm confused can somebody please help me?

Thank you
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Values from dynamic controls
Values from dynamic controls
Values from dynamic controls Values from dynamic controls
Values from dynamic controls
Values from dynamic controls
Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls Values from dynamic controls
Values from dynamic controls
Values from dynamic controls
 
Values from dynamic controls
Values from dynamic controls
 
-->