PDA

Click to See Complete Forum and Search --> : adding a control to a tableCell deletes all the text?


MrPolite
Jul 21st, 2003, 09:20 PM
Umm I;m creating a table at runtime. I'm creating TableCells, it's been working fine till now. I have some stuff added to the TableCell.Text and it worked fine, but now that I'm also adding a linkButton control to the cell, all the text disappears and only the link button shows up.

What's wrong with what I'm doing? how can I preserve the text in the tableCell when I add the linkButton control to it?

MrPolite
Jul 26th, 2003, 11:16 PM
anyone knows what I'm talking about?

Lethal
Jul 27th, 2003, 01:39 AM
Without seeing your code, its hard to tell where your going wrong. I just whipped this up and it works fine:


HtmlTable t = new HtmlTable();
HtmlTableRow r = new HtmlTableRow();
HtmlTableCell c = new HtmlTableCell();
LiteralControl l = new LiteralControl("Name: ");
c.Controls.Add(l);
LinkButton lnk = new LinkButton();
lnk.Text = "Click Me";
c.Controls.Add(lnk);
r.Cells.Add(c);
t.Rows.Add(r);
FindControl("Form1").Controls.Add(t);

MrPolite
Jul 29th, 2003, 12:47 AM
umm well yeah I didnt add the text with a literal control:D I just set the .TEXT property, anything wrong with that?

hellswraith
Jul 29th, 2003, 10:46 AM
Originally posted by MrPolite
umm well yeah I didnt add the text with a literal control:D I just set the .TEXT property, anything wrong with that?
Yes, it isn't working for you.... :)

Lethal
Jul 29th, 2003, 11:10 AM
Originally posted by MrPolite
umm well yeah I didnt add the text with a literal control:D I just set the .TEXT property, anything wrong with that?

I agree with hellswraith...:D

MrPolite
Jul 30th, 2003, 12:55 PM
well thanks hellswraith I didn't know that it wasn't working... :)

what's the purpose of the Text property of a table cell then?

hellswraith
Jul 30th, 2003, 01:30 PM
To put text in it when you are not adding controls to it.

hellswraith
Jul 30th, 2003, 01:32 PM
MSDN Library says:

Remarks
Use the Text property to specify or determine the text contents of the cell. This property is commonly used to programmatically update the contents of a cell.

Note Setting the Text property will clear any other controls contained in the TableCell.
CAUTION This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input. For more information, see Validation Server Controls.

MrPolite
Jul 30th, 2003, 02:33 PM
:) thanks alot, makes sense now, hehe