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

HTML first, Page_Load later

In the following aspx file the output from Page_Load code is rendered first
and HTML later. I want the other way round.

How can I do that?

<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server"><title>Welcome to my Project</title></head>

<body>

<form id="form1" runat="server"><div>

<h3>Below are the files in my Project</h3>

</div></form>

</body></html>

<script runat="server">

protected void Page_Load(object sender, EventArgs e) {
DirectoryInfo dir = new DirectoryInfo(this.MapPath("~"));

foreach (FileInfo f in dir.GetFiles("*.as*x"))

if (f.Name.ToLower() != "default.aspx") Response.Write("<a href='./" +
f.Name + "'>" + f.Name + "</a>" + "<br>");

}

</script>
Mar 19 '07 #1
3 1221
Instead of doing raw Response.Write's to the output stream, try databinding
your "stuff" to a control defined on the Page that is suitable for rendering
such a list - a Repeater, DataList, or Gridview.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"dotNET learner" wrote:
In the following aspx file the output from Page_Load code is rendered first
and HTML later. I want the other way round.

How can I do that?

<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server"><title>Welcome to my Project</title></head>

<body>

<form id="form1" runat="server"><div>

<h3>Below are the files in my Project</h3>

</div></form>

</body></html>

<script runat="server">

protected void Page_Load(object sender, EventArgs e) {
DirectoryInfo dir = new DirectoryInfo(this.MapPath("~"));

foreach (FileInfo f in dir.GetFiles("*.as*x"))

if (f.Name.ToLower() != "default.aspx") Response.Write("<a href='./" +
f.Name + "'>" + f.Name + "</a>" + "<br>");

}

</script>
Mar 19 '07 #2
On Mar 19, 4:07 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Instead of doing raw Response.Write's to the output stream, try databinding
your "stuff" to a control defined on the Page that is suitable for rendering
such a list - a Repeater, DataList, or Gridview.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"dotNET learner" wrote:
In the following aspx file the output from Page_Load code is rendered first
and HTML later. I want the other way round.
How can I do that?
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title>Welcome to my Project</title></head>
<body>
<form id="form1" runat="server"><div>
<h3>Below are the files in my Project</h3>
</div></form>
</body></html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
DirectoryInfo dir = new DirectoryInfo(this.MapPath("~"));
foreach (FileInfo f in dir.GetFiles("*.as*x"))
if (f.Name.ToLower() != "default.aspx") Response.Write("<a href='./" +
f.Name + "'>" + f.Name + "</a>" + "<br>");
}
</script>
I would also suggest using code behind files instead of including the
C# logic in the ASPX page itself. This separates the code from the
design which is always a good direction to go.

Mar 19 '07 #3
Following your suggestion, I used simple Label control instead of
"Response.Write". It worked. Thank you :) The modified code is below:

protected void Page_Load(object sender, EventArgs e) {
string fileList = "";

DirectoryInfo dir = new DirectoryInfo(this.MapPath("~"));

foreach (FileInfo f in dir.GetFiles("*.as*x"))

if (f.Name.ToLower() != "default.aspx") {

fileList = fileList + "<a href='./" + f.Name + "'>" + f.Name + "</a>" +
"<br>";

}

lblFileList.Text = fileList;

}


"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:54**********************************@microsof t.com...
Instead of doing raw Response.Write's to the output stream, try
databinding
your "stuff" to a control defined on the Page that is suitable for
rendering
such a list - a Repeater, DataList, or Gridview.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"dotNET learner" wrote:
>In the following aspx file the output from Page_Load code is rendered
first
and HTML later. I want the other way round.

How can I do that?

<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server"><title>Welcome to my Project</title></head>

<body>

<form id="form1" runat="server"><div>

<h3>Below are the files in my Project</h3>

</div></form>

</body></html>

<script runat="server">

protected void Page_Load(object sender, EventArgs e) {
DirectoryInfo dir = new DirectoryInfo(this.MapPath("~"));

foreach (FileInfo f in dir.GetFiles("*.as*x"))

if (f.Name.ToLower() != "default.aspx") Response.Write("<a href='./" +
f.Name + "'>" + f.Name + "</a>" + "<br>");

}

</script>

Mar 20 '07 #4

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

Similar topics

72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
2
by: sushi | last post by:
Hello, I am developing an asp.net website. I have a web fomr say' webform1.aspx' having two input button html controls. When I click on 'button1' a message appears. Following code is executed o...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
4
by: VR | last post by:
Hi. I have an ASP.NET web page, with a logo written in plain HTML. One of the tags is an image that should read either "sign on" or "sign off" depending on whether a user has been...
1
by: Patrick | last post by:
Problem I have an ASPX file, with a table of 3 columns, 2 rows with a usercontrol in the middle column (in the code snippet stated below, although in reality, the left hand column would also...
7
by: J-T | last post by:
I have a user control called "Test1" with two button on it ,one is input and the other one is a server control as follow: <input type="button"...
15
by: Rob Nicholson | last post by:
I'm starting to worry a bit now. We're getting the above error when two users hit the same database/page on an ASP.NET application using ADO.NET, talking to a SQL 7 server. The error is perfectly...
10
by: D. Shane Fowlkes | last post by:
I have a function that is called in page_load and the purpose of this function is to look up basic data in a MSSQL table and return it in the form of a datatable. The page_load will read the data...
6
by: john | last post by:
The standard method to transmit a file from an aspx page to a browser is to stream the file to the response then end the response. The HTML code generated by the aspx page is discarded, and the...
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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
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...

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.