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
>>
>
|