473,466 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how do I "write" an ASP.Net onto the page in code?

How can I do a loop from 1 to 5, where on line 1 I print 1 space
followed by a button, on line 2 I print 2 spaces followed by a button,
on line 3 I print 3 spaces followed by a button, etc.?

I tried this code:

for (int i = 1; i <= 5 ; ++i)
{
for (int j = 1; j <= i; ++j)
{
Response.Write("&nbsp;");
}
Response.Write("<asp:Button id=\"Button" +
i.ToString() +
"\" runat=\"server\" Text=\"Button\"></asp:Button>" +
"<br>\n");
}

but that didn't work, since Response.Write just sent the characters
"<asp:Button" etc. to the browser; ASP.Net did not interpret them.

Or maybe someone could think of a better way to do what I'm trying to
do:

I have a database table of message posts; some messages are "replies"
to other messages, and each record in the table has a parent_post_id
that refers to the ID of the parent post, if there is one. What I'm
actually trying to do is display the messages in a hierarchical way,
i.e. the first top-level post, followed by all of its direct replies
that are indented by X spaces, and each reply is also followed by all
of *its* replies indented by 2X spaces, etc., the familiar way in which
a hierarchy of message posts is usually displayed. Each message post
is displayed as a custom control.

The ideal solution would be to do it recursively, having a custom
control for a "post" that displays the current post and then has a list
of "post" controls for all the replies, indented X spaces further over
than the parent. This would result in all the replies to the replies
being displayed as well, all the way down to the last replies.
Unfortunately ASP.Net does not allow user controls to contain
themselves recursively.

So my plan is to do it iteratively: get the first top-level post, then
get a list of all its replies, then go through and print the replies,
but after checking each reply, check if *it* has any replies, and go
and print those... etc. But to do that I need a way to "print" the
user control that represents a message post. Hence my original
question.

Nov 19 '05 #1
4 2731
The server side cotnrol syntax like "<asp:Button>" is a declarative syntax
to tell ASP.NET what contorls you'd like on the page. This syntax is parsed
at compile time by ASP.NET (prior to the page actually handling a request).
Doing Respone.Write is during a request, and so it's far too late for the
ASP.NET parser to get involved.

Since this snippet of code you've provided is very much in the old ASP style
(and very much not in the ASP.NET style) I'd suggest doing some research
and reading on how the model's different. The ASP.NET QuickStarts is a great
place to get started:

http://www.asp.net/Tutorials/quickstart.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen
How can I do a loop from 1 to 5, where on line 1 I print 1 space
followed by a button, on line 2 I print 2 spaces followed by a button,
on line 3 I print 3 spaces followed by a button, etc.?

I tried this code:

for (int i = 1; i <= 5 ; ++i)
{
for (int j = 1; j <= i; ++j)
{
Response.Write("&nbsp;");
}
Response.Write("<asp:Button id=\"Button" +
i.ToString() +
"\" runat=\"server\" Text=\"Button\"></asp:Button>" +
"<br>\n");
}
but that didn't work, since Response.Write just sent the characters
"<asp:Button" etc. to the browser; ASP.Net did not interpret them.

Or maybe someone could think of a better way to do what I'm trying to
do:

I have a database table of message posts; some messages are "replies"
to other messages, and each record in the table has a parent_post_id
that refers to the ID of the parent post, if there is one. What I'm
actually trying to do is display the messages in a hierarchical way,
i.e. the first top-level post, followed by all of its direct replies
that are indented by X spaces, and each reply is also followed by all
of *its* replies indented by 2X spaces, etc., the familiar way in
which a hierarchy of message posts is usually displayed. Each message
post is displayed as a custom control.

The ideal solution would be to do it recursively, having a custom
control for a "post" that displays the current post and then has a
list of "post" controls for all the replies, indented X spaces further
over than the parent. This would result in all the replies to the
replies being displayed as well, all the way down to the last replies.
Unfortunately ASP.Net does not allow user controls to contain
themselves recursively.

So my plan is to do it iteratively: get the first top-level post, then
get a list of all its replies, then go through and print the replies,
but after checking each reply, check if *it* has any replies, and go
and print those... etc. But to do that I need a way to "print" the
user control that represents a message post. Hence my original
question.


Nov 19 '05 #2
I already know that the snippet of code I posted is not in the ASP.Net
style, I've written most of my project already using Visual Studio .Net
and using samples from books to do almost everything I needed to do. I
know how to populate datagrids and datarepeaters, and I don't have any
bad habits left over from ASP because I never worked with ASP :)

The trouble is that nothing in the books or tutorials that I went
through, gave any indication of how to do something like what I
described above, where you want to display something recursively -- for
example, display a "message board post" user control, with all of its
reply posts nested below it, and all of the replies to the replies
nested below *them*, etc. The samples in the books are good for
learning how to work with rigid structures like datagrids, and even for
more flexible things like datarepeaters, but not for doing something
nested like the post hierarchy I described, where the best solution
would be a control that recursively contains itself except ASP.Net of
course does not allow those.

If using Response.Write() to write the controls is impossible, then
what would be the proper way to create a "recursive" structure like the
one described above? Like a datarepeater but with the rows in a
hierarchical relationship to each other instead of just a flat list.

Even just a function name or a control name would be enough to get me
started, if it's documented!

Nov 19 '05 #3
re:
display a "message board post" user control, with all of its
reply posts nested below it, and all of the replies to the replies
nested below *them*, etc.
The Community Forums application does exactly that.
Take a look at Telligent System's Community Server :

http://www.telligentsystems.com/Solu...ums-source.exe

Free for non-commercial use, and will give you tons of ideas.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

<be*****@peacefire.org> wrote in message
news:11********************@g43g2000cwa.googlegrou ps.com...I already know that the snippet of code I posted is not in the ASP.Net
style, I've written most of my project already using Visual Studio .Net
and using samples from books to do almost everything I needed to do. I
know how to populate datagrids and datarepeaters, and I don't have any
bad habits left over from ASP because I never worked with ASP :)

The trouble is that nothing in the books or tutorials that I went
through, gave any indication of how to do something like what I
described above, where you want to display something recursively -- for
example, display a "message board post" user control, with all of its
reply posts nested below it, and all of the replies to the replies
nested below *them*, etc. The samples in the books are good for
learning how to work with rigid structures like datagrids, and even for
more flexible things like datarepeaters, but not for doing something
nested like the post hierarchy I described, where the best solution
would be a control that recursively contains itself except ASP.Net of
course does not allow those.

If using Response.Write() to write the controls is impossible, then
what would be the proper way to create a "recursive" structure like the
one described above? Like a datarepeater but with the rows in a
hierarchical relationship to each other instead of just a flat list.

Even just a function name or a control name would be enough to get me
started, if it's documented!

Nov 19 '05 #4
Thanks for the pointer. Unfortunately the site I'm building is not
just one where I want to add a discussion board, but I'm actually
writing a new *kind* of discussion board, so I pretty much have to
write it from the ground up, and I've got almost all of it done except
this one detail. I'd love to get ideas from the Community Server app,
but looking at the online demo at http://forums.asp.net/ it doesn't
look like they actually do the hierarchical indented display of form
posts the way I'm trying to set up mine. Looking at
http://forums.asp.net/914877/ShowPost.aspx
it's just a flat vertical display, basically a DataRepeater, and I know
how to do that.

I am not asking anyone to write any code for me but is there a
one-sentence description of *how* to do what I'm trying to do?

IF recursive user controls were possible, it could be done in one
sentence: "Make a custom control called 'RecursiveUserPost' that
displays the post's author, subject, and timestamp, and then contains a
DataRepeater that is indented over by a few spaces, and query for all
posts that have the current post as their 'parent' and use that to
populate the DataRepeater, and have the ItemTemplate for the
DataRepeater recursively contain an instance of RecursiveUserPost that
is bound to that data."

Is there any way to describe in one sentence how to do it given that
recursive user controls are not possible?

Nov 19 '05 #5

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

Similar topics

1
by: Mark Richards | last post by:
The solutions for the following problems seems to be simple but I did not found a (convenient) solution: Assume we have a number of elements of the same type under a common parent e.g. <person...
5
by: Eric | last post by:
Is it possible? I'm trying to add to the current page -- but add at a specific point. Can add HTML tags from javascript midway through the page (at a place I specify) without erasing the existing...
2
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
9
by: mallyonline | last post by:
I last posted to this group about 6 months ago and was very pleased by the excellent response I got and the great help offered to me. I am back this time with another request for your expert help...
10
by: Eric E | last post by:
Hi all, I am using an Access client linked to a PG 7.4 server via ODBC. I have a stored proc on the server that inserts rows into a table.particular table, accomplished via an INSERT within the...
7
by: samuelberthelot | last post by:
Hi, I have the following in my asp page: <% response.write(Header) %> where Header contains HTML markup such ass <html> <body> .... I must write the code in the aspx file and not in the...
5
by: coldstar | last post by:
In an ASP Querystring, how do I include the double quotes in the code below at "1.0" part as text in my string? I have tried ""1.0"" and almost everything else but can't get it to work. I need...
27
by: duli | last post by:
Hi: I would like recommendations for books (in any language, not necessarily C++, C, python) which have walkthroughs for developing a big software project ? So starting from inception, problem...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.