473,385 Members | 1,542 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,385 software developers and data experts.

Runtime Controls Addition.

I am building an application that used the placement of panel controls at runtime. Inside of these panels I would like to add multiple buttons. This is part of a scheduling application that I will not be
reusing (if I can help it). I get an error on the addition of the button controls.... "Must be placed inside a container with runat="server" attribute";
I can not set the runat="server" for a control that is created at runtime (Panel).

Any suggestions?

Sample Code:
Panel objPanel = new Panel();
objPanel.HorizontalAlign = HorizontalAlign.Center;
Button objButton = new Button();
objButton.Text = "Test";

....eventHandler stuff etc.

objPanel.Controls.Add(objButton);
PlaceHolder1.Controls.Add(objPanel);
Nov 19 '05 #1
4 1382
Are you sure the error isn't that they need to be placed in a <form> with
runat=server? My guess is that your Panel is outside the <form runat=server>
in the ASPX page.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I am building an application that used the placement of panel controls
at runtime. Inside of these panels I would like to add multiple
buttons. This is part of a scheduling application that I will not be

reusing (if I can help it). I get an error on the addition of the
button controls.... "Must be placed inside a container with
runat="server" attribute";

I can not set the runat="server" for a control that is created at
runtime (Panel).

Any suggestions?

Sample Code:

Panel objPanel = new Panel();
objPanel.HorizontalAlign = HorizontalAlign.Center;
Button objButton = new Button();
objButton.Text = "Test";
...eventHandler stuff etc.

objPanel.Controls.Add(objButton);
PlaceHolder1.Controls.Add(objPanel);


Nov 19 '05 #2
The panel is being build at runtime and added to a placeholder that is inside of a form with the runat server attribute set. The placeholder also has the runat="server" attribute. I can add buttons all day with no problem until I try to add it to a panel that was created at runtime.

Nov 19 '05 #3
Lee

Hi ;)

Can't you just set the runat=server attribute using something similar to:

runtimePanel.Attributes.Add ("runat", "server");
Possibly this won't work, just an idea..


Leon <fa*****@mail.bay.k12.fl.us> wrote in
news:uk**************@TK2MSFTNGP12.phx.gbl:
The panel is being build at runtime and added to a placeholder that is
inside of a form with the runat server attribute set. The
placeholder also has the runat="server" attribute. I can add buttons
all day with no problem until I try to add it to a panel that was
created at runtime.


Nov 19 '05 #4
> Can't you just set the runat=server attribute using something similar
to:

runtimePanel.Attributes.Add ("runat", "server");

Possibly this won't work, just an idea..


This won't work. the runat=server is something inspected by the ASP.NET parser
while it's reading your ASPX to construct the class for the page. It's the
directive to tell the parser that the page should contain a control for that
location in the page. At runtime then, to create new controls that weren't
declared in the ASPX (with runat=server) you just need to create them (IOW,
call "new") and then add them into the control hierarchy in the control tree
to say where it should appear to be rendered. The placeholder approach mentioned
is a fine approach.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #5

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

Similar topics

3
by: Mathew | last post by:
Hi How do you specfiy the version of the .net runtime libraries loaded for a ..net controls hosted in Internet Explorer 6? I have a control that's designed to work with .NET 1.1, but after...
3
by: | last post by:
Hi,all I want to change Control's size&location in runtime ,(C#) but i dont know how to do! :(so, can you provide me with document about this. my email: zhonghua@rinpak.com.cn ...
2
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to...
8
by: Benoit Martin | last post by:
I had to draw my own control because I couldn't find any control doing what I wanted it to do. This control has a grid that I need to have control over. To do that, I draw each line of the grid...
1
by: Mian Mahboob | last post by:
Nicholas Paldino in my application a have an Windows form on that i place an Panel Control. in Form load event i ganerate an Form in Panel Control on Runtime then get an design time create...
3
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the...
6
by: TonyMast | last post by:
VB 2005 - XP Pro - Windows forms I'm trying to write a simple multiplication tables program for my little girl. How can I create 200 labels, 100 textboxes. Here is what I've tried so far...
7
by: Matt | last post by:
Hi all, I'm trying to create a system where it reads a number of records from a database and then creates a row in the GUI that contains a single field from the database and a button that has a...
0
by: nsandeep08 | last post by:
how to enable grid layout panel at runtime for repositioning of the controls and addition of new controls and deletion of existing controls in asp.net(c#) web application
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.