Retreving Value of Textbox dynamically added into Table


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Retreving Value of Textbox dynamically added into Table

Hybrid View

  1. #1
    Robert Guest

    Retreving Value of Textbox dynamically added into Table


    I am not able to retrieve the value of dynamically added text box to table.
    Kindly help me to find mistake on this code.


    Error

    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information about
    the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: Specified argument
    was out of the range of valid values. Parameter name: index

    Source Error:


    Line 52: Dim txtBox As New TextBox()
    Line 53:
    Line 54:txtBox = CType(Table1.Rows(1).FindControl ("txtBox1"), TextBox)
    Line 55: Response.Write(txtBox.Text)
    Line 56:


    Source File: c:\inetpub\wwwroot\DragDrop\WebForm2.aspx.vb Line: 54

    Stack Trace:


    [ArgumentOutOfRangeException: Specified argument was out of the range of
    valid values.
    Parameter name: index]
    System.Web.UI.ControlCollection.get_Item(Int32 index)
    System.Web.UI.WebControls.TableRowCollection.get_Item(Int32 index)
    DragDrop.WebForm2.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\DragDrop\WebForm2.aspx.vb:54

    System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(St ring
    eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,
    String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    System.Web.UI.Page.ProcessRequestMain()





    Source Code

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Handles MyBase.Load
    'Put user code to initialize the page here
    If Not Page.IsPostBack Then
    Dim IdWidth As New Unit("5%")
    Dim QWidth As New Unit("95%")
    Dim Height As New Unit("20%")
    Dim myARow As New TableRow()
    Dim myACell1 As New TableCell()
    Dim myACell2 As New TableCell()
    Dim myACell3 As New TableCell()
    myACell1.Width = IdWidth
    myACell2.Width = QWidth
    myARow.Cells.Add(myACell1)
    myARow.Cells.Add(myACell2)
    myARow.Cells.Add(myACell3)
    Dim txtBox As New TextBox()
    Dim hidtxtBoxValue As New HtmlInputHidden()
    Dim hidtxtQW As New HtmlInputHidden()
    txtBox.ID = "txtBox" & 1
    txtBox.Width = QWidth
    myACell2.Controls.Add(txtBox)
    Table1.Rows.Add(myARow)

    End If

    End Sub

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

    txtBox = CType(Table1.Rows(1).FindControl("txtBox1"),TextBox)
    Response.Write(txtBox.Text)

    End Sub


  2. #2
    Raymond Naseef Guest

    Re: Retreving Value of Textbox dynamically added into Table

    It sounds like your table has only one row in it. As with most indexes, row
    indexes are 0-based (i.e., the first row is Rows(0)).

    "Robert" <j_robertraj@rediffmail.com> wrote in message
    news:3c9b10f6$1@10.1.10.29...
    >
    > I am not able to retrieve the value of dynamically added text box to

    table.
    > Kindly help me to find mistake on this code.
    >
    >
    > Error
    >
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information

    about
    > the error and where it originated in the code.
    >
    > Exception Details: System.ArgumentOutOfRangeException: Specified argument
    > was out of the range of valid values. Parameter name: index
    >
    > Source Error:
    >
    >
    > Line 52: Dim txtBox As New TextBox()
    > Line 53:
    > Line 54:txtBox = CType(Table1.Rows(1).FindControl ("txtBox1"), TextBox)
    > Line 55: Response.Write(txtBox.Text)
    > Line 56:
    >
    >
    > Source File: c:\inetpub\wwwroot\DragDrop\WebForm2.aspx.vb Line: 54
    >
    > Stack Trace:
    >
    >
    > [ArgumentOutOfRangeException: Specified argument was out of the range of
    > valid values.
    > Parameter name: index]
    > System.Web.UI.ControlCollection.get_Item(Int32 index)
    > System.Web.UI.WebControls.TableRowCollection.get_Item(Int32 index)
    > DragDrop.WebForm2.Button1_Click(Object sender, EventArgs e) in

    c:\inetpub\wwwroot\DragDrop\WebForm2.aspx.vb:54
    >
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    >

    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
    stBackEvent(String
    > eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler

    sourceControl,
    > String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > System.Web.UI.Page.ProcessRequestMain()
    >
    >
    >
    >
    >
    > Source Code
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As

    System.EventArgs)
    > Handles MyBase.Load
    > 'Put user code to initialize the page here
    > If Not Page.IsPostBack Then
    > Dim IdWidth As New Unit("5%")
    > Dim QWidth As New Unit("95%")
    > Dim Height As New Unit("20%")
    > Dim myARow As New TableRow()
    > Dim myACell1 As New TableCell()
    > Dim myACell2 As New TableCell()
    > Dim myACell3 As New TableCell()
    > myACell1.Width = IdWidth
    > myACell2.Width = QWidth
    > myARow.Cells.Add(myACell1)
    > myARow.Cells.Add(myACell2)
    > myARow.Cells.Add(myACell3)
    > Dim txtBox As New TextBox()
    > Dim hidtxtBoxValue As New HtmlInputHidden()
    > Dim hidtxtQW As New HtmlInputHidden()
    > txtBox.ID = "txtBox" & 1
    > txtBox.Width = QWidth
    > myACell2.Controls.Add(txtBox)
    > Table1.Rows.Add(myARow)
    >
    > End If
    >
    > End Sub
    >
    > Private Sub Button1_Click(ByVal sender As Object, ByVal e As

    System.EventArgs)
    > Handles Button1.Click
    > Dim txtBox As New TextBox()
    >
    > txtBox = CType(Table1.Rows(1).FindControl("txtBox1"),TextBox)
    > Response.Write(txtBox.Text)
    >
    > End Sub
    >




  3. #3
    Join Date
    Sep 2006
    Posts
    10

    help plz

    hi all

    i do have the same problem mentioned above

    Exception Details: System.ArgumentOutOfRangeException: Specified argument
    was out of the range of valid values. Parameter name: index

    i tried to use 0 index but not working
    infact when i click on the button the row counts in my table becomes zero
    and i dont know why????

    please i appreaciate any kind of help
    best regards,
    Rana

  4. #4
    Join Date
    Sep 2006
    Posts
    10

    urgent

    plz if anyone has any clue???
    this is my code:

    ' grd is a gridveiw in the form, it contains data and it works fine
    ' tb is the table

    Public Sub up_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles up.Click

    For j As Integer = 1 To Me.grd.Rows.Count
    Dim mygrade As New TextBox

    mygrade.ID = "mygrade_" & j
    mygrade.BorderStyle = BorderStyle.None

    Dim myrow As New TableRow
    Dim mycell As New TableCell


    mycell.Controls.Add(mygrade)
    myrow.Cells.Add(mycell)
    tb.Rows.Add(myrow)

    Next

    END Sub

    ' the above code is working great
    my problem is in the followingrow counts is zero)


    Protected Sub Ad_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Ad.Click

    For Each c As Control In tb.Rows(0).Cells(0).Controls
    Response.Write(c.GetType().ToString & "<br/>")
    If c.GetType().ToString = "System.Web.UI.WebControls.TextBox" Then
    MsgBox(c.GetType.ToString)
    Dim t As TextBox = CType(c, TextBox)
    t.Text = "whatever"
    End If
    Next


    End Sub

  5. #5
    Join Date
    Sep 2006
    Posts
    10
    hey guys i did found the solution
    the problem is that we always have a page reload on button click
    and the solution was to add the rows and the cells at page load and not at the click.

    regards,
    rana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center