Addin Controls to Footer

J

Jim Heavey

Hello, I am trying to add a control to a footer in code, but I get the
following error" "Exception Details: System.Web.HttpException: Control
'txtAddMovieTitle' of type 'TextBox' must be placed inside a form tag with
runat=server."

The code that I am using is as follows:

'* add the Movie Title entry box
Dim txtbox1 As New TextBox()
txtbox1.ID = "txtAddMovieTitle"
txtbox1.Width = New Unit(180)
txtbox1.Font.Size = New FontUnit(FontSize.Small)
e.Item.Cells(2).Controls.Add(txtbox1)
The error message seems to suggest that it is expecting to have a
"Runat="Server", but That property is not avaialble for me to set in code.

Any ideas as to what the problem is an how to correct?
 
C

Craig Deelsnyder

Jim said:
Hello, I am trying to add a control to a footer in code, but I get the
following error" "Exception Details: System.Web.HttpException: Control
'txtAddMovieTitle' of type 'TextBox' must be placed inside a form tag with
runat=server."

The code that I am using is as follows:

'* add the Movie Title entry box
Dim txtbox1 As New TextBox()
txtbox1.ID = "txtAddMovieTitle"
txtbox1.Width = New Unit(180)
txtbox1.Font.Size = New FontUnit(FontSize.Small)
e.Item.Cells(2).Controls.Add(txtbox1)
The error message seems to suggest that it is expecting to have a
"Runat="Server", but That property is not avaialble for me to set in code.

Any ideas as to what the problem is an how to correct?

Actually, it means you have to add it to a FORM which has runat="server"
set. Do you have a FORM surrounding your repeating control?
 
J

Jim Heavey

The form which the DataGrid that I am adding the control to is within a
form and that form is in the aspx file as follows: " <form
id="Form1" method="post" runat="server">".

I originally had these controls specified in the "aspx" file, but now I
find a need to specify them in code.

So if the form is "runat=Server" and the datagrid is "runat=Server", what
could the problem be?
 
C

Craig Deelsnyder

Jim said:
The form which the DataGrid that I am adding the control to is within a
form and that form is in the aspx file as follows: " <form
id="Form1" method="post" runat="server">".

I originally had these controls specified in the "aspx" file, but now I
find a need to specify them in code.

So if the form is "runat=Server" and the datagrid is "runat=Server", what
could the problem be?

Wait, are you saying that you have more than one form? If so, you can't
do this with ASP.NET, only one form per page, with id= and runat=server
on it, surrounding the server controls you're working with.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top