473,403 Members | 2,338 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,403 software developers and data experts.

Server control inside another

52
Hi,

I've just noticed if there is a control that runat server and another one directly inside it, it will result in a compilation error.

eg.

If I have an asp:Label directly inside a table, it doesn't like it:

<table id="myTable" runat="server">
<asp:Label id="myLabel" runat="server" />
</table>
Where the error message is CS1502: The best overloaded method match for 'System.Web.UI.HtmlControls.HtmlTableRowCollection .Add(System.Web.UI.HtmlControls.HtmlTableRow)' has some invalid arguments


On the other hand, if I place the asp:Label inside a row or a cell of the table, it would work fine:

<table id="myTable" runat="server">
<tr><td>
<asp:Label id="myLabel" runat="server" />
</td></tr>
</table>

Any idea what's causing the problem? and if I must have a control directly inside another, how can I overcome this problem?


Thanks in advance :)
Jan 27 '09 #1
7 5572
naga01
3
In your case with Table, its mandatory to have it wrapped inside a TR and TD

The controls are suppose to placed where it is suppose to placed.

Table is a container where it can contain only TR, only TD is a control container.
Jan 27 '09 #2
200dogz
52
@naga01
Hmm thanks for your help.

The reason I use <asp:Label> inside a <table> is to expend the table on server side, based on the data retrieved from the databases. This has been used for most of the pages in my site.

what I'm trying to do right now is to provide the ability to export tables to Excel. I can only get it to work if I make the tables to run at server. Is there a way I might be able to do that if I don't want to change what I already have too much, like putting the tables in panel and export them instead?
Jan 27 '09 #3
Frinavale
9,735 Expert Mod 8TB
Why don't you use CSS and JavaScript to "expand" your table instead of placing it inside a Label control? This is not now a Label Control is supposed to be used.

Then you would have a pure table that you could export easily.
Jan 27 '09 #4
200dogz
52
@Frinavale
sorry I guess "expand" isn't the correct word. I like to use Lables for table with indefinite number of rows.
Jan 27 '09 #5
Frinavale
9,735 Expert Mod 8TB
Sorry, I still don't understand why you are using Labels the way you are.
Could you better explain what you mean by "expand"?
Jan 27 '09 #6
200dogz
52
@Frinavale
Say if I have...

<table>
<tr><th>Heading</th></tr>
<asp:Label id="rows" runat="server" />
</table>
and in the code I can do:

OdbcDataReader reader = ... // read from database
while (reader.Read())
{
rows.Text += "<tr><td>" + reader["stuff"] + "</td></tr>";
}
I'm kind of new to ASP.NET and this was the first method of table control that I thought of and have been using it since then. It might not be conventional and might not be good, but I don't plan on changing this; at least not for this project I'm working on since it's almost done.
Jan 28 '09 #7
Frinavale
9,735 Expert Mod 8TB
This is not a good solution because when the Label is rendered it becomes an HTML <span>. Your table will become invalid because <span> tags are not valid within a table.

For example, the following is valid:
Expand|Select|Wrap|Line Numbers
  1. <table>
  2. <tr>
  3.   <td></td>
  4. </tr>
  5. </table>
But what's going to happen with the Label is that you're going to end up with:
Expand|Select|Wrap|Line Numbers
  1. <table>
  2.     <span>
  3.         <tr>
  4.            <td></td>
  5.         </tr>
  6.      </span>
  7. </table>
If you're dead set on using this solution to create your table then at least switch out the Label for a Literal Control. Literals are rendered as text.

In the future you should consider using a Repeater to create your table.


-Frinny
Jan 28 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Georges Heinesch | last post by:
Hi. Is it possible to put a tab control inside another tab control. I tried it several times, but for some reason this doesn't seem to work. Can someone confirm this, or tell me what the trick...
0
by: nail | last post by:
Hi. Think the following scenario. UC1 with a textbox control and a button control. UC2 with a textbox control and a button control too. I need to, on the click event of the button inside the...
4
by: Neil Stevens | last post by:
Hi, Merry Christmas to you all. I have a problem with server controls, i am writing a C# ASP.NET web project and i am creating custom server controls for some of the more common element. One...
1
by: Martin | last post by:
In a VB.NET windows forms I have a custom control which I have added a number of instances to a panel control. I want to raise a event when one of the controls on one of the custom controls is...
0
by: muthu | last post by:
Hi guys, Iam using a repeator control in my page.In wich i have dropdown list as the last column.I have a label in the first column.Now i have binded a datable to the repeator in the page load...
0
by: Charlie | last post by:
Hi: When I add controls to item template in DataList, I only see the stock ASP.NET controls. I would like to use one of my own Custom Server Controls instead. How do I do this in 1.0? ...
2
by: Charlie | last post by:
Hi: When using templated columns in DataList, ASP.net server controls can be inserted. Rather than using the base ASP.net server controls, I would like to use one of my own custom server...
0
by: superman | last post by:
Hello, I am facing a strange situation and have already spent a lot of time on this. I have a user control 'U' that consists of a server/composite control 'C'. C consists of a textbox 'T' and a...
4
by: Louis Dupont | last post by:
I'm trying to use a server control inside a template wizard step, when I drop such server control in the first step of the wizard everything goes ok. When I insert even a blank step previous to the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.