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>