473,667 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Html Code dynmically in Placeholder

Hi,

i want to structure two elements (each conists of 1 Label and 1 Textbox) in
an Table. As I use an Content Place Holder, i thought it is possible to add
the table via Controls.add(Li teral). Literal consists of standard html code
like <table>, <tr>, etc.. Nevertheless Asp Net generates me now table in
html code, maybe you see my mistake in the code below. Thanks a lot!

_MC_

Literal tableStart = new Literal(); tableStart.Text =
"<table>";

Literal tableStop = new Literal(); tableStop.Text =
"</table>";

Literal rowStart = new Literal(); rowStart.Text = "<tr>";

Literal rowStop = new Literal(); rowStart.Text = "</tr>";

Literal jumpColumnStart = new Literal(); jumpColumnStart .Text = "<td>";


PlaceHolder2_Ed itableItems.Con trols.Add(table Start); // <table>

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt art); // <tr>

for (int i = 0; i < columnNames.Cou nt; i++) {

lastcount++;

Label infoLabel = new Label();

infoLabel.Text = "test1";
TextBox myValTextBox = new TextBox();

myValTextBox.Te xt = "test2"

PlaceHolder2_Ed itableItems.Con trols.Add(jumpC olumnStart); // <td>

PlaceHolder2_Ed itableItems.Con trols.Add(infoL abel);

PlaceHolder2_Ed itableItems.Con trols.Add(jumpC olumnStart); // <td>

PlaceHolder2_Ed itableItems.Con trols.Add(myVal TextBox);

if (lastcount == tableColumns)

{

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt op); // </tr>

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt art); // <tr>

lastcount = 0;

}
}

PlaceHolder2_Ed itableItems.Con trols.Add(table Stop);


Apr 6 '07 #1
2 15036
I don't believe it will work as you expect because you are adding the same
object repeatedly. That will confuse the control you are adding it to such
as the placeholder. Your best bet is to create the
literal controls that control the start and stop of the table cells within
the loop. That would limit how often you add the same control to the
placeholder because it will be a new literal control each time it goes
through the loop.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"_MC_" <mc@localhostwr ote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Hi,

i want to structure two elements (each conists of 1 Label and 1 Textbox)
in an Table. As I use an Content Place Holder, i thought it is possible to
add the table via Controls.add(Li teral). Literal consists of standard html
code like <table>, <tr>, etc.. Nevertheless Asp Net generates me now table
in html code, maybe you see my mistake in the code below. Thanks a lot!

_MC_

Literal tableStart = new Literal(); tableStart.Text =
"<table>";

Literal tableStop = new Literal(); tableStop.Text =
"</table>";

Literal rowStart = new Literal(); rowStart.Text =
"<tr>";

Literal rowStop = new Literal(); rowStart.Text =
"</tr>";

Literal jumpColumnStart = new Literal(); jumpColumnStart .Text =
"<td>";


PlaceHolder2_Ed itableItems.Con trols.Add(table Start); // <table>

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt art); // <tr>

for (int i = 0; i < columnNames.Cou nt; i++) {

lastcount++;

Label infoLabel = new Label();

infoLabel.Text = "test1";
TextBox myValTextBox = new TextBox();

myValTextBox.Te xt = "test2"

PlaceHolder2_Ed itableItems.Con trols.Add(jumpC olumnStart); // <td>

PlaceHolder2_Ed itableItems.Con trols.Add(infoL abel);

PlaceHolder2_Ed itableItems.Con trols.Add(jumpC olumnStart); // <td>

PlaceHolder2_Ed itableItems.Con trols.Add(myVal TextBox);

if (lastcount == tableColumns)

{

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt op); // </tr>

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt art); // <tr>

lastcount = 0;

}
}

PlaceHolder2_Ed itableItems.Con trols.Add(table Stop);


Apr 6 '07 #2
you need to nest properly. add the tr's to the table controls
collection, td'd to the tr's controls collection, etc.

also there is an HtmlTable controlthat you can use instead.

-- bruce (sqlwork.com)

_MC_ wrote:
Hi,

i want to structure two elements (each conists of 1 Label and 1 Textbox) in
an Table. As I use an Content Place Holder, i thought it is possible to add
the table via Controls.add(Li teral). Literal consists of standard html code
like <table>, <tr>, etc.. Nevertheless Asp Net generates me now table in
html code, maybe you see my mistake in the code below. Thanks a lot!

_MC_

Literal tableStart = new Literal(); tableStart.Text =
"<table>";

Literal tableStop = new Literal(); tableStop.Text =
"</table>";

Literal rowStart = new Literal(); rowStart.Text = "<tr>";

Literal rowStop = new Literal(); rowStart.Text = "</tr>";

Literal jumpColumnStart = new Literal(); jumpColumnStart .Text = "<td>";


PlaceHolder2_Ed itableItems.Con trols.Add(table Start); // <table>

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt art); // <tr>

for (int i = 0; i < columnNames.Cou nt; i++) {

lastcount++;

Label infoLabel = new Label();

infoLabel.Text = "test1";
TextBox myValTextBox = new TextBox();

myValTextBox.Te xt = "test2"

PlaceHolder2_Ed itableItems.Con trols.Add(jumpC olumnStart); // <td>

PlaceHolder2_Ed itableItems.Con trols.Add(infoL abel);

PlaceHolder2_Ed itableItems.Con trols.Add(jumpC olumnStart); // <td>

PlaceHolder2_Ed itableItems.Con trols.Add(myVal TextBox);

if (lastcount == tableColumns)

{

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt op); // </tr>

PlaceHolder2_Ed itableItems.Con trols.Add(rowSt art); // <tr>

lastcount = 0;

}
}

PlaceHolder2_Ed itableItems.Con trols.Add(table Stop);

Apr 6 '07 #3

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

Similar topics

3
4873
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
4
3141
by: Mark Rae | last post by:
Hi, I have an <asp:PlaceHolder control on a page in an ASP.NET 1.1 app, as follows: <td nowrap><asp:PlaceHolder ID="phClientWebsite" Runat=server>&nbsp;</asp:PlaceHolder></td> Server-side, I'm running the following code:
0
1441
by: Klaus Jensen | last post by:
Hi! This has been annoying me for a while now, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and adds a handler to the click event. When a button is clicked, the background-color is set to blue.
0
2395
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta version, the program is not working as in version 1.1. So what is the problem? Microsoft declared that the version 2.0 is fully backward support, but it is not. Is that the problem with 2.0 version? I find out the problem in version 2.0. After...
3
5161
by: John Hughes | last post by:
I'm trying to add a user control to a form via the pages render method and I get the following error : "Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server" The user control has this button on its page. I am outputing the <form runat="server"> inside the render method and have also tried adding it to the page and to the control without any luck. Any help appreciated.
3
2339
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
2
1830
by: tshad | last post by:
Is there a way to dynamically add in User Controls where I would get the name from a session variable: If I have the following code: ****************************************************************************** <%@ Page Language="C#" trace="false" debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
3
5486
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
2
15067
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
0
8458
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8565
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.