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

Shoving dynamic code in the middle of a page.

UJ
I'm a newbie to this so please excuse the level of question. My question is
how can I dynamically create a table in the middle of a page without having
to build the entire page dynamically? I have code to build the string that
will generate the table. (This is all to solve the problem of when a person
clicks a checkbox in a datagrid, there's no way of knowing what record it
belongs to - see my previous post)

Here's what my code would look like ideally:

<html>
<body>
<form>
Isn't this a pretty page?

(Some kind of code that would build all the controls I need. Ideally
this code would be a function that is in the codebehind page)

Done creating my stuff.
</form>
</body>
<html>

Thanks again in advance.

Jeffrey.
Nov 19 '05 #1
4 1439
Hi Jeffrey,

You can put a Placeholder control there and in your codebehind, add controls
you create to the placeholder's Controls collection.

Ken

"UJ" <fr**@nowhere.com> wrote in message
news:uY*************@TK2MSFTNGP09.phx.gbl...
I'm a newbie to this so please excuse the level of question. My question
is how can I dynamically create a table in the middle of a page without
having to build the entire page dynamically? I have code to build the
string that will generate the table. (This is all to solve the problem of
when a person clicks a checkbox in a datagrid, there's no way of knowing
what record it belongs to - see my previous post)

Here's what my code would look like ideally:

<html>
<body>
<form>
Isn't this a pretty page?

(Some kind of code that would build all the controls I need.
Ideally this code would be a function that is in the codebehind page)

Done creating my stuff.
</form>
</body>
<html>

Thanks again in advance.

Jeffrey.

Nov 19 '05 #2
Jeffrey:
Typically you stick a placeholder control and then dynamically build your
controls, placing them inthe placeholder..
....
<form>
<asp:placeholder id="content" runat="server" />
</form>
codebehind:

protected content as PlaceHolder

page_load
dim table as new HtmlTable
dim row as new HtmlTableRow

dim cell as new HtmlRableCell
cell.InnerText = "Hello"
row.Cells.Add(cell)
cell = new HtmlTableCell
cell.InnerText = "World"
row.Cells.Add(cell)

table.Rows.Add(row)

content.Controls.Ad(table)
end sub
or, if you are looping through records, use a repeater/datagrid/datalist.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"UJ" <fr**@nowhere.com> wrote in message
news:uY*************@TK2MSFTNGP09.phx.gbl...
I'm a newbie to this so please excuse the level of question. My question
is how can I dynamically create a table in the middle of a page without
having to build the entire page dynamically? I have code to build the
string that will generate the table. (This is all to solve the problem of
when a person clicks a checkbox in a datagrid, there's no way of knowing
what record it belongs to - see my previous post)

Here's what my code would look like ideally:

<html>
<body>
<form>
Isn't this a pretty page?

(Some kind of code that would build all the controls I need.
Ideally this code would be a function that is in the codebehind page)

Done creating my stuff.
</form>
</body>
<html>

Thanks again in advance.

Jeffrey.

Nov 19 '05 #3
also couldn't you define the table control in the HTML and simply
dynamically build it out (adding the rows & columns) in the
code-behind..?

What does the placeholder give you?

It seems to me that the placeholder is good when you know that
sometimes the control at that "place" is a textbox and sometimes the
control in the "place" is something else..
Seems that if you know that you are building a table, then you may as
well go ahead and define the table...? What am i missing?

Nov 19 '05 #4
UJ
Karl,
Thanks for the help.

Jeffrey

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2*****************@TK2MSFTNGP12.phx.gbl...
Jeffrey:
Typically you stick a placeholder control and then dynamically build your
controls, placing them inthe placeholder..
...
<form>
<asp:placeholder id="content" runat="server" />
</form>
codebehind:

protected content as PlaceHolder

page_load
dim table as new HtmlTable
dim row as new HtmlTableRow

dim cell as new HtmlRableCell
cell.InnerText = "Hello"
row.Cells.Add(cell)
cell = new HtmlTableCell
cell.InnerText = "World"
row.Cells.Add(cell)

table.Rows.Add(row)

content.Controls.Ad(table)
end sub
or, if you are looping through records, use a repeater/datagrid/datalist.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"UJ" <fr**@nowhere.com> wrote in message
news:uY*************@TK2MSFTNGP09.phx.gbl...
I'm a newbie to this so please excuse the level of question. My question
is how can I dynamically create a table in the middle of a page without
having to build the entire page dynamically? I have code to build the
string that will generate the table. (This is all to solve the problem of
when a person clicks a checkbox in a datagrid, there's no way of knowing
what record it belongs to - see my previous post)

Here's what my code would look like ideally:

<html>
<body>
<form>
Isn't this a pretty page?

(Some kind of code that would build all the controls I need.
Ideally this code would be a function that is in the codebehind page)

Done creating my stuff.
</form>
</body>
<html>

Thanks again in advance.

Jeffrey.


Nov 19 '05 #5

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

Similar topics

4
by: Tim Pascoe | last post by:
I am using ASP to dynamically generate a series of forms. When the page is loaded, everything appears to be correct, except that the first form generated fails with a "FormName is Null or not an...
2
by: Zach | last post by:
I have a situation similar to what you see in Visual Studio Options menu. A Tree View on the left, and depending on what type of node you click it dynamically loads a panel into the right hand...
0
by: chxant | last post by:
Hi, I'm trying to develop a webapplication with a dynamic panel. The first time the PanelResult is empty. After the user clicked on the Login button I want to show a couple of radiobuttons...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
3
by: Adam Baker | last post by:
This is a fairly broad question. I have looked for web sites or books on the topic, by to no avail. I'm creating a fairly small web site in which the content is drawn from an XML file (more or...
21
by: karen987 | last post by:
I have a news website, with asp pages. It has publishing software which allows you to add articles in a database, and then calls them up from links etc. I have added dynamic meta tags in 2 parts. The...
1
by: suneel271 | last post by:
code working in internet explorer but not in mozilla and iam getting erroe like window.event has no properties and here is the code <%@ page language="java" contentType="text/html;...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.