473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding controls at runtime

I have created a Datagrid in code, added it to the Controls collection and
set it's DataSource. All works fine. I try the same thing with a button
(create an instance, add it to the controls collection), it doesn't want to
know. I just get an error stating:

"Control '_ctl1' of type 'Button' must be placed inside a Form tag with
runat=server".

Can anyone suggest why it let me create and display the DataGrid but not a
Button?
Aug 1 '06 #1
1 1272
Hi,

you need to add it inside the server-side form.

If you have

<form id="Form1" runat="server">

</form>

You'd need to add it to the form's Controls collection (Button requires
such, datagrid doesn't unless it is set to contain buttons). E.g

Dim btn As New Button()
Page.FindControl("Form1").Controls.Add(btn)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"cashdeskmac" <ca*********@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
>I have created a Datagrid in code, added it to the Controls collection and
set it's DataSource. All works fine. I try the same thing with a button
(create an instance, add it to the controls collection), it doesn't want
to
know. I just get an error stating:

"Control '_ctl1' of type 'Button' must be placed inside a Form tag with
runat=server".

Can anyone suggest why it let me create and display the DataGrid but not a
Button?

Aug 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: avivgur | last post by:
Hello, I am writing a program in Visual C# and I have encountered a problem. In my program I want to dynamically create a multitude of controls (thousands) on a form. The problem is that calling...
8
by: Thomas H. | last post by:
Hi folks, what's the best way to add (web)controls at runtime ?? TIA T.H.
4
by: slylos | last post by:
I've got a Windows form that has a TabControl. I add TabPages to this TabControl at Runtime, along with two Textboxes and a button. The problem I'm having is I can't figure out how to reference...
2
by: Mark Siffer | last post by:
I am trying to add a compare validator at runtime. I would add it before but my input controls are built at runtime via an editable datagrid. Therefore, the names of the controls are not known...
0
by: Kurt | last post by:
Hi Brent, I don't know if this is best practices per se`, but it works. The following generates a new button control each time menu item 1 is clicked and assigns an event handler to it. ...
4
by: rushikesh.joshi | last post by:
Hi All, I have created my own WebControl and want to add it in my aspx page at runtime. it's compiling perfectly, but when i m going to execute, it gives me error of "Object reference not set...
3
by: Toe Dipper | last post by:
In short we have a lengthy process when a form is loaded that adds activex controls to our windows form. This process in itself works fine however we would like to push this processing to a thread...
0
by: sonic | last post by:
I am trying to dynamically load a validator and must be missing something elementary here. I extended TextBox control to add some functionality to it. One new feature it contains is IsRequired...
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.