Problems with aspx.cs

liunx

Guest
I am using a very nice application created in ASP .NET to upload files to a database. The problem is that everything is sent from .aspx to a .aspx.cs file using codebehind (Codebehind="default.aspx.cs"). My question is, when I want to modify anything from the .aspx file everything works fine but when I try to change even the color of the font in the .aspx.cs files It does not work... I am using buffer.Append to show variables, etc. do you think this could be the problem? The program I am using is on: <!-- m --><a class="postlink" href="http://www.stardeveloper.com/articles/display.html?article=2003031201&page=1">http://www.stardeveloper.com/articles/d ... 201&page=1</a><!-- m --> in case you want to have a look

Any help would be really appreciated
Gloriahi
the attribute: Codebehind="default.aspx.cs" is used by vs.net, and is not recongized by asp.net

I have the following questions for you:
1) did u Download the code?
1a) if yes... did you have trouble display the page in the browser?
1b) if no... did you have trouble display the page in the browser?

2) assume u can display your page in browser... did you give a name (id tag) to your control in aspx so that the cs file can references to?

3) if (2) was yes... can u show us the <%@ Page ....> code and the control <asp:....> code from ur aspx page. and also show us ur Page_Load function (i'm assuming you wanna modify color or font in page_load function, if not...attach the code from other function)Thank you sirpelidor,

I am using the code from the page but I have not Download ed the code from the website, I copied and pasted some parts from it to my site and concerning the display, I did not have any problems to display the page to the browser once I had built the solution.

Here is some of the code. There is a default.aspx page that generally has this info:
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="Stardeveloper.UploadAccess.DefaultForm" %>

and then in the body
<div id="allFiles" runat="server" />

and in the page default.aspx.cs the code is:

using System;debug;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.OleDb;

namespace Stardeveloper.UploadAccess
{
public class DefaultForm : GenericPage
{
protected const string CmdText = "SELECT * FROM Files";

protected HtmlGenericControl allFiles;

private void Page_Load(object sender, System.EventArgs e)
{
allFiles.InnerHtml = GetFilesFromAccessDb();
}

private string GetFilesFromAccessDb()
{
StringBuilder buffer = new StringBuilder(4096);

buffer.Append("<table align=\"center\" width=\"95%\" border=\"0\" ");
buffer.Append("cellspacing=\"2\" cellpadding=\"2\">");
buffer.Append("<tr><td width=\"20%\"><span ");
buffer.Append("class=\"dimColor\">File</span></td>");
buffer.Append("<td width=\"10%\" align=\"left\"><span ");
buffer.Append("class=\"dimColor\">Completed by</span></td>");
buffer.Append("<td width=\"10%\" align=\"left\"><span ");
buffer.Append("class=\"dimColor\">Date</span></td>");
buffer.Append("<td width=\"10%\" align=\"left\"><span ");
buffer.Append("class=\"dimColor\">Sharepoint</span></td>");
buffer.Append("<td width=\"10%\" align=\"left\"><span ");
buffer.Append("class=\"dimColor\">BK1</span></td>");
buffer.Append("<td width=\"10%\" align=\"left\"><span ");
buffer.Append("class=\"dimColor\">VDC</span></td>");
buffer.Append("<td width=\"10%\" align=\"left\"><span ");
buffer.Append("class=\"dimColor\">Other</span></td>");
buffer.Append("<td width=\"20%\" align=\"left\"><span ");
buffer.Append("class=\"dimColor\">Comments</span>");
buffer.Append("</td></tr>");

using(OleDbConnection con = new OleDbConnection(ConnectionString))
using(OleDbCommand cmd = new OleDbCommand(CmdText, con))
{
con.Open();
OleDbDataReader rd = cmd.ExecuteReader(CommandBehavior.SingleResult |
CommandBehavior.CloseConnection);

while(rd.Read())
{
int fileId;
string fileName;
int fileLength;
string contentType;
string NameStaff;
string UploadDate;
string Sharepoint;
string Bk1;
string VDC;
string Other;
string Comments;

fileId = rd.GetInt32(0);
fileName = rd.GetString(1);
fileLength = rd.GetInt32(2);
contentType = rd.GetString(3);
NameStaff = rd.GetString(4);
UploadDate = rd.GetString(5);
Sharepoint = rd.GetString(6);
Bk1 = rd.GetString(7);
VDC = rd.GetString(8);
Other = rd.GetString(9);
Comments = rd.GetString(10);

buffer.Append("<tr><td><a href=http://www.webdeveloper.com/forum/archive/index.php/\"file.aspx?file_id=");
buffer.Append(fileId);
buffer.Append("&mode=view\">");
buffer.Append(fileName);
buffer.Append("</a> [ <a href=http://www.webdeveloper.com/forum/archive/index.php/\"file.aspx?file_id=");
buffer.Append(fileId);
buffer.Append("&mode=delete\">Delete</a> ]");
buffer.Append(" [ <a href=http://www.webdeveloper.com/forum/archive/index.php/\"file.aspx?file_id=");
buffer.Append(fileId);
buffer.Append("&mode=Download \">Download </a> ]");

buffer.Append("</td><td align=\"left\">");
buffer.Append(NameStaff);
buffer.Append("</td><td align=\"left\">");
buffer.Append(UploadDate);
buffer.Append("</td><td align=\"left\">");
buffer.Append(Sharepoint);
buffer.Append("</td><td align=\"left\">");
buffer.Append(Bk1);
buffer.Append("</td><td align=\"left\">");
buffer.Append(VDC);
buffer.Append("</td><td align=\"left\">");
buffer.Append(Other);
buffer.Append("</td><td align=\"left\">");
buffer.Append(Comments);
buffer.Append("</td></tr>");
}

rd.Close();
buffer.Append("</table>");
}

return buffer.ToString();
}

The problem is that the tables are not being displayed, I don't know if I am missing something.

I have another page that makes the connection to the database so that seems to be ok
Thanks for your helphi, i don't have much experience with StringBuilder. But lets try troubleshoot this way:

u created a object: StringBuilder buffer = new StringBuilder(4096);
and u use the Append method to add string into ur object.

(1) with the code that u have now, will buffer become 1 long html string or many strings with line-breaks?

(2) are there other methods u can use instead of building html strings ?
i.e: use asp:Table web control or use asp: DataList web control to achieve the same result
 
Back
Top