Textbox in table

Discussion in 'ASP .Net Web Controls' started by Tony, Feb 15, 2005.

  1. Tony

    Tony Guest

    Win XP - VS 2002 - VB - web forms
    I'm creating a table, 2 labels, 1 text box dynamically (only show 1 of each
    in code below)
    I'm able to add the labels to the table at run time however I cannot add the
    text boxes.
    here is the code and then the error message,

    Dim tblVD As New Table()
    tblVD.Visible = True
    tblVD.BackColor = Color.Ivory
    tblVD.GridLines = GridLines.Both
    Me.Controls.Add(tblVD)

    Dim rforloop As Int16
    Dim cforloop As Int16
    For rforloop = 0 To 4
    Dim trow As New TableRow()
    For cforloop = 0 To 3
    Dim tcell As New TableCell()
    trow.Cells.Add(tcell)
    Next cforloop
    tblVD.Rows.Add(trow)
    Next rforloop

    Dim lab As New Label()
    lab.Text = "lab"
    tblVD.Rows(0).Cells(0).Controls.Add(lab)

    Dim txt As New TextBox()
    txt.BorderStyle = BorderStyle.Groove
    txt.Text = "Enter Info Here"
    tblVD.Rows(0).Cells(1).Controls.Add(txt)

    tblVD.Style.Add("10", "Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP:
    96px")
    ---------------Error
    Below-------------------------------------------------------------------------------------------

    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Control '_ctl2' of type 'TextBox' must be placed inside a form tag with
    runat=server.
    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.Web.HttpException: Control '_ctl2' of type
    'TextBox' must be placed inside a form tag with runat=server.

    Source Error:


    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of the
    exception can be identified using the exception stack trace below.


    Stack Trace:


    [HttpException (0x80004005): Control '_ctl2' of type 'TextBox' must be
    placed inside a form tag with runat=server.]
    System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +151
    System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter
    writer) +40
    System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
    writer) +17
    System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter writer)
    +55
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    writer) +7
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
    +102
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.Page.ProcessRequestMain() +1926





    --------------------------------------------------------------------------------

    Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
    Version:1.1.4322.2032



    Thanks for any help
    Tony
     
    Tony, Feb 15, 2005
    #1
    1. Advertising

  2. Hi Tony,

    You're adding the table to part of the page but forgetting that the form is
    just one child control of the page. If you check with trace="true", you'll
    see that to put the table inside the form, you need to go to the second
    control (1 in zero-based counting):

    Page.Controls(1).Controls.Add(tblVD)

    The table seems to be able to survive outside of the form (that's where it
    was going) but the textbox can't.

    An easier way to do this would be to drop a Placeholder onto the page and
    then add things to the Placeholder's controls collection.

    Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]
    Toronto


    "Tony" <> wrote in message
    news:...
    > Win XP - VS 2002 - VB - web forms
    > I'm creating a table, 2 labels, 1 text box dynamically (only show 1 of
    > each in code below)
    > I'm able to add the labels to the table at run time however I cannot add
    > the text boxes.
    > here is the code and then the error message,
    >
    > Dim tblVD As New Table()
    > tblVD.Visible = True
    > tblVD.BackColor = Color.Ivory
    > tblVD.GridLines = GridLines.Both
    > Me.Controls.Add(tblVD)
    >
    > Dim rforloop As Int16
    > Dim cforloop As Int16
    > For rforloop = 0 To 4
    > Dim trow As New TableRow()
    > For cforloop = 0 To 3
    > Dim tcell As New TableCell()
    > trow.Cells.Add(tcell)
    > Next cforloop
    > tblVD.Rows.Add(trow)
    > Next rforloop
    >
    > Dim lab As New Label()
    > lab.Text = "lab"
    > tblVD.Rows(0).Cells(0).Controls.Add(lab)
    >
    > Dim txt As New TextBox()
    > txt.BorderStyle = BorderStyle.Groove
    > txt.Text = "Enter Info Here"
    > tblVD.Rows(0).Cells(1).Controls.Add(txt)
    >
    > tblVD.Style.Add("10", "Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP:
    > 96px")
    > ---------------Error
    > Below-------------------------------------------------------------------------------------------
    >
    > Server Error in '/' Application.
    > --------------------------------------------------------------------------------
    >
    > Control '_ctl2' of type 'TextBox' must be placed inside a form tag with
    > runat=server.
    > 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.Web.HttpException: Control '_ctl2' of type
    > 'TextBox' must be placed inside a form tag with runat=server.
    >
    > Source Error:
    >
    >
    > An unhandled exception was generated during the execution of the
    > current web request. Information regarding the origin and location of the
    > exception can be identified using the exception stack trace below.
    >
    >
    > Stack Trace:
    >
    >
    > [HttpException (0x80004005): Control '_ctl2' of type 'TextBox' must be
    > placed inside a form tag with runat=server.]
    > System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +151
    > System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter
    > writer) +40
    > System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
    > writer) +17
    > System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    > System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
    > writer) +55
    > System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    > System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    > writer) +7
    > System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
    > +102
    > System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    > System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.Page.ProcessRequestMain() +1926
    >
    >
    >
    >
    >
    > --------------------------------------------------------------------------------
    >
    > Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
    > ASP.NET Version:1.1.4322.2032
    >
    >
    >
    > Thanks for any help
    > Tony
    >
     
    Ken Cox [Microsoft MVP], Feb 16, 2005
    #2
    1. Advertising

  3. Tony

    Tony Guest

    I'm using your suggestion
    Page.Controls(1).Controls.Add(tblVD) (not sure how the placeholder
    control works)
    All worked well until I hit a button and caused a postback then table and
    controls disappeared.
    I have the creation of all the controls and table in the Load page in a if
    not is postback.

    Also I'm unable to use the control except for in the load_page .
    for example I have dim txt as textbox() , then I add txt.text = "thanks for
    your help".
    then I created a button1 on the design page, if I try to put code in it like
    if txt.text = "thanks for your help" I get an error txt not declared. But it
    is in the page_load sub.


    Thanks
    Tony

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:...
    > Hi Tony,
    >
    > You're adding the table to part of the page but forgetting that the form
    > is just one child control of the page. If you check with trace="true",
    > you'll see that to put the table inside the form, you need to go to the
    > second control (1 in zero-based counting):
    >
    > Page.Controls(1).Controls.Add(tblVD)
    >
    > The table seems to be able to survive outside of the form (that's where it
    > was going) but the textbox can't.
    >
    > An easier way to do this would be to drop a Placeholder onto the page and
    > then add things to the Placeholder's controls collection.
    >
    > Let us know if this helps?
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    > Toronto
    >
    >
    > "Tony" <> wrote in message
    > news:...
    >> Win XP - VS 2002 - VB - web forms
    >> I'm creating a table, 2 labels, 1 text box dynamically (only show 1 of
    >> each in code below)
    >> I'm able to add the labels to the table at run time however I cannot add
    >> the text boxes.
    >> here is the code and then the error message,
    >>
    >> Dim tblVD As New Table()
    >> tblVD.Visible = True
    >> tblVD.BackColor = Color.Ivory
    >> tblVD.GridLines = GridLines.Both
    >> Me.Controls.Add(tblVD)
    >>
    >> Dim rforloop As Int16
    >> Dim cforloop As Int16
    >> For rforloop = 0 To 4
    >> Dim trow As New TableRow()
    >> For cforloop = 0 To 3
    >> Dim tcell As New TableCell()
    >> trow.Cells.Add(tcell)
    >> Next cforloop
    >> tblVD.Rows.Add(trow)
    >> Next rforloop
    >>
    >> Dim lab As New Label()
    >> lab.Text = "lab"
    >> tblVD.Rows(0).Cells(0).Controls.Add(lab)
    >>
    >> Dim txt As New TextBox()
    >> txt.BorderStyle = BorderStyle.Groove
    >> txt.Text = "Enter Info Here"
    >> tblVD.Rows(0).Cells(1).Controls.Add(txt)
    >>
    >> tblVD.Style.Add("10", "Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP:
    >> 96px")
    >> ---------------Error
    >> Below-------------------------------------------------------------------------------------------
    >>
    >> Server Error in '/' Application.
    >> --------------------------------------------------------------------------------
    >>
    >> Control '_ctl2' of type 'TextBox' must be placed inside a form tag with
    >> runat=server.
    >> 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.Web.HttpException: Control '_ctl2' of type
    >> 'TextBox' must be placed inside a form tag with runat=server.
    >>
    >> Source Error:
    >>
    >>
    >> An unhandled exception was generated during the execution of the
    >> current web request. Information regarding the origin and location of the
    >> exception can be identified using the exception stack trace below.
    >>
    >>
    >> Stack Trace:
    >>
    >>
    >> [HttpException (0x80004005): Control '_ctl2' of type 'TextBox' must be
    >> placed inside a form tag with runat=server.]
    >> System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +151
    >> System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter
    >> writer) +40
    >> System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
    >> writer) +17
    >> System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17
    >> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >> System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    >> System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
    >> writer) +55
    >> System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    >> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >> System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    >> System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    >> writer) +7
    >> System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    >> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >> System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
    >> +102
    >> System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    >> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >> System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    >> System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    >> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >> System.Web.UI.Page.ProcessRequestMain() +1926
    >>
    >>
    >>
    >>
    >>
    >> --------------------------------------------------------------------------------
    >>
    >> Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
    >> ASP.NET Version:1.1.4322.2032
    >>
    >>
    >>
    >> Thanks for any help
    >> Tony
    >>

    >
     
    Tony, Feb 16, 2005
    #3
  4. Tony

    Tony Guest

    I figured it out I moved the dm as global and everything seems to work now
    thanks.


    "Tony" <> wrote in message
    news:eHUYqc%...
    > I'm using your suggestion
    > Page.Controls(1).Controls.Add(tblVD) (not sure how the placeholder
    > control works)
    > All worked well until I hit a button and caused a postback then table and
    > controls disappeared.
    > I have the creation of all the controls and table in the Load page in a if
    > not is postback.
    >
    > Also I'm unable to use the control except for in the load_page .
    > for example I have dim txt as textbox() , then I add txt.text = "thanks
    > for your help".
    > then I created a button1 on the design page, if I try to put code in it
    > like
    > if txt.text = "thanks for your help" I get an error txt not declared. But
    > it is in the page_load sub.
    >
    >
    > Thanks
    > Tony
    >
    > "Ken Cox [Microsoft MVP]" <> wrote in message
    > news:...
    >> Hi Tony,
    >>
    >> You're adding the table to part of the page but forgetting that the form
    >> is just one child control of the page. If you check with trace="true",
    >> you'll see that to put the table inside the form, you need to go to the
    >> second control (1 in zero-based counting):
    >>
    >> Page.Controls(1).Controls.Add(tblVD)
    >>
    >> The table seems to be able to survive outside of the form (that's where
    >> it was going) but the textbox can't.
    >>
    >> An easier way to do this would be to drop a Placeholder onto the page and
    >> then add things to the Placeholder's controls collection.
    >>
    >> Let us know if this helps?
    >>
    >> Ken
    >> Microsoft MVP [ASP.NET]
    >> Toronto
    >>
    >>
    >> "Tony" <> wrote in message
    >> news:...
    >>> Win XP - VS 2002 - VB - web forms
    >>> I'm creating a table, 2 labels, 1 text box dynamically (only show 1 of
    >>> each in code below)
    >>> I'm able to add the labels to the table at run time however I cannot add
    >>> the text boxes.
    >>> here is the code and then the error message,
    >>>
    >>> Dim tblVD As New Table()
    >>> tblVD.Visible = True
    >>> tblVD.BackColor = Color.Ivory
    >>> tblVD.GridLines = GridLines.Both
    >>> Me.Controls.Add(tblVD)
    >>>
    >>> Dim rforloop As Int16
    >>> Dim cforloop As Int16
    >>> For rforloop = 0 To 4
    >>> Dim trow As New TableRow()
    >>> For cforloop = 0 To 3
    >>> Dim tcell As New TableCell()
    >>> trow.Cells.Add(tcell)
    >>> Next cforloop
    >>> tblVD.Rows.Add(trow)
    >>> Next rforloop
    >>>
    >>> Dim lab As New Label()
    >>> lab.Text = "lab"
    >>> tblVD.Rows(0).Cells(0).Controls.Add(lab)
    >>>
    >>> Dim txt As New TextBox()
    >>> txt.BorderStyle = BorderStyle.Groove
    >>> txt.Text = "Enter Info Here"
    >>> tblVD.Rows(0).Cells(1).Controls.Add(txt)
    >>>
    >>> tblVD.Style.Add("10", "Z-INDEX: 101; LEFT: 96px; POSITION: absolute;
    >>> TOP: 96px")
    >>> ---------------Error
    >>> Below-------------------------------------------------------------------------------------------
    >>>
    >>> Server Error in '/' Application.
    >>> --------------------------------------------------------------------------------
    >>>
    >>> Control '_ctl2' of type 'TextBox' must be placed inside a form tag with
    >>> runat=server.
    >>> 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.Web.HttpException: Control '_ctl2' of type
    >>> 'TextBox' must be placed inside a form tag with runat=server.
    >>>
    >>> Source Error:
    >>>
    >>>
    >>> An unhandled exception was generated during the execution of the
    >>> current web request. Information regarding the origin and location of
    >>> the exception can be identified using the exception stack trace below.
    >>>
    >>>
    >>> Stack Trace:
    >>>
    >>>
    >>> [HttpException (0x80004005): Control '_ctl2' of type 'TextBox' must be
    >>> placed inside a form tag with runat=server.]
    >>> System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +151
    >>> System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter
    >>> writer) +40
    >>> System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
    >>> writer) +17
    >>> System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17
    >>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >>> System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    >>> System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
    >>> writer) +55
    >>> System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    >>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >>> System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    >>> System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    >>> writer) +7
    >>> System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    >>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >>> System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
    >>> +102
    >>> System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
    >>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >>> System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
    >>> System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    >>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    >>> System.Web.UI.Page.ProcessRequestMain() +1926
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> --------------------------------------------------------------------------------
    >>>
    >>> Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
    >>> ASP.NET Version:1.1.4322.2032
    >>>
    >>>
    >>>
    >>> Thanks for any help
    >>> Tony
    >>>

    >>

    >
    >
     
    Tony, Feb 16, 2005
    #4
    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. S. Justin Gengo
    Replies:
    0
    Views:
    536
    S. Justin Gengo
    Jul 16, 2003
  2. Hazzard
    Replies:
    2
    Views:
    551
    Yan-Hong Huang[MSFT]
    Jul 23, 2003
  3. Natty Gur
    Replies:
    0
    Views:
    462
    Natty Gur
    Jul 22, 2003
  4. David Williams
    Replies:
    2
    Views:
    1,136
    Jacob Yang [MSFT]
    Aug 12, 2003
  5. Rio
    Replies:
    4
    Views:
    1,199
Loading...

Share This Page