Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Textbox in table

Reply
Thread Tools

Textbox in table

 
 
Tony
Guest
Posts: n/a
 
      02-15-2005
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(Con trol control) +151
System.Web.UI.WebControls.TextBox.AddAttributesToR ender(HtmlTextWriter
writer) +40
System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
writer) +17
System.Web.UI.WebControls.TextBox.Render(HtmlTextW riter writer) +17
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
System.Web.UI.WebControls.TableCell.RenderContents (HtmlTextWriter writer)
+55
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer) +7
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.WebControls.Table.RenderContents(Htm lTextWriter writer)
+102
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWrite r 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


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      02-16-2005
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" <TonyMast_NOPE_@msn.com> 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(Con trol control) +151
> System.Web.UI.WebControls.TextBox.AddAttributesToR ender(HtmlTextWriter
> writer) +40
> System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
> writer) +17
> System.Web.UI.WebControls.TextBox.Render(HtmlTextW riter writer) +17
> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
> System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
> System.Web.UI.WebControls.TableCell.RenderContents (HtmlTextWriter
> writer) +55
> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
> System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
> System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
> writer) +7
> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
> System.Web.UI.WebControls.Table.RenderContents(Htm lTextWriter writer)
> +102
> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
> System.Web.UI.Control.RenderChildren(HtmlTextWrite r 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
>


 
Reply With Quote
 
 
 
 
Tony
Guest
Posts: n/a
 
      02-16-2005
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" <TonyMast_NOPE_@msn.com> 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(Con trol control) +151
>> System.Web.UI.WebControls.TextBox.AddAttributesToR ender(HtmlTextWriter
>> writer) +40
>> System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
>> writer) +17
>> System.Web.UI.WebControls.TextBox.Render(HtmlTextW riter writer) +17
>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>> System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
>> System.Web.UI.WebControls.TableCell.RenderContents (HtmlTextWriter
>> writer) +55
>> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>> System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
>> System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
>> writer) +7
>> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>> System.Web.UI.WebControls.Table.RenderContents(Htm lTextWriter writer)
>> +102
>> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>> System.Web.UI.Control.RenderChildren(HtmlTextWrite r 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
>>

>



 
Reply With Quote
 
Tony
Guest
Posts: n/a
 
      02-16-2005
I figured it out I moved the dm as global and everything seems to work now
thanks.


"Tony" <TonyMast_NOPE_@msn.com> 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" <TonyMast_NOPE_@msn.com> 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(Con trol control) +151
>>> System.Web.UI.WebControls.TextBox.AddAttributesToR ender(HtmlTextWriter
>>> writer) +40
>>> System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
>>> writer) +17
>>> System.Web.UI.WebControls.TextBox.Render(HtmlTextW riter writer) +17
>>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>>> System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
>>> System.Web.UI.WebControls.TableCell.RenderContents (HtmlTextWriter
>>> writer) +55
>>> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
>>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>>> System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +72
>>> System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
>>> writer) +7
>>> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
>>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>>> System.Web.UI.WebControls.Table.RenderContents(Htm lTextWriter writer)
>>> +102
>>> System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +29
>>> System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>>> System.Web.UI.Control.RenderChildren(HtmlTextWrite r 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
>>>

>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Table/table rows/table data tag question? Rio HTML 4 11-05-2004 08:11 AM
Could not load type VTFixup Table from assembly Invalid token in v-table fix-up table. David Williams ASP .Net 2 08-12-2003 07:55 AM
runat="server"....a simple html textbox or a webform server textbox...that is the question. Hazzard ASP .Net 2 07-23-2003 07:32 AM
Re: runat="server"....a simple html textbox or a webform server textbox...that is the question. Natty Gur ASP .Net 0 07-22-2003 03:57 AM
Re: VERY STRANGE BUG? Adding a textbox control causes other textbox control to fail??? S. Justin Gengo ASP .Net 0 07-16-2003 06:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57