Adding HTML Code to a web page already running

  • Thread starter Thread starter dfdavis.mtu
  • Start date Start date
D

dfdavis.mtu

This is probably a simple question, but I just started using C# and I
haven't done any projects like this before, however, I need to know if
there is a way to accomplish what I am currently doing in a faster
time. Right now I have a web page I created in VS 2005 where I am
pulling data from a database dependant upon who is logged in and
showing them the members and information for their specific company.
However, to display this on the web page I created a label and I simply
add the html code to that label. This seems to take a good 5 minutes
as some of the companies have 1200 some people and that means 3600
lines of html are added to this label. So basically is there a faster
way to take that code and add it to the page? Right now I have an
outside program create a file with the company name beforehand and this
file contains all the HTML I want to add. Sorry if this is confusing,
but I would greatly appreciate any help or ideas.

Thanks,

Dan
 
This is probably a simple question, but I just started using C# and I
haven't done any projects like this before, however, I need to know if
there is a way to accomplish what I am currently doing in a faster
time. Right now I have a web page I created in VS 2005 where I am
pulling data from a database dependant upon who is logged in and
showing them the members and information for their specific company.
However, to display this on the web page I created a label and I simply
add the html code to that label. This seems to take a good 5 minutes
as some of the companies have 1200 some people and that means 3600
lines of html are added to this label. So basically is there a faster
way to take that code and add it to the page? Right now I have an
outside program create a file with the company name beforehand and this
file contains all the HTML I want to add. Sorry if this is confusing,
but I would greatly appreciate any help or ideas.

Thanks,

Dan

How are you building that HTML?
If you are using a string where you add each line to, then it is much
faster to use StringBuilder:

instead of:

string s = "";
for (int i=0; i<rows.Count; i++)
{
s = s + HtmlForRow(rows);
}
LabelOutput.Text = s;

use this:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i=0; i<rows.Count; i++)
{
sb.Append(HtmlForRow(rows));
}
LabelOutput.Text = sb.ToString();

see also http://www.yoda.arachsys.com/csharp/stringbuilder.html


Hans Kesting
 
Hans said:
This is probably a simple question, but I just started using C# and I
haven't done any projects like this before, however, I need to know if
there is a way to accomplish what I am currently doing in a faster
time. Right now I have a web page I created in VS 2005 where I am
pulling data from a database dependant upon who is logged in and
showing them the members and information for their specific company.
However, to display this on the web page I created a label and I simply
add the html code to that label. This seems to take a good 5 minutes
as some of the companies have 1200 some people and that means 3600
lines of html are added to this label. So basically is there a faster
way to take that code and add it to the page? Right now I have an
outside program create a file with the company name beforehand and this
file contains all the HTML I want to add. Sorry if this is confusing,
but I would greatly appreciate any help or ideas.

Thanks,

Dan

How are you building that HTML?
If you are using a string where you add each line to, then it is much
faster to use StringBuilder:

instead of:

string s = "";
for (int i=0; i<rows.Count; i++)
{
s = s + HtmlForRow(rows);
}
LabelOutput.Text = s;

use this:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i=0; i<rows.Count; i++)
{
sb.Append(HtmlForRow(rows));
}
LabelOutput.Text = sb.ToString();

see also http://www.yoda.arachsys.com/csharp/stringbuilder.html


Hans Kesting


Basically what I do is, go through with a reader from my query, then I
parse it into a line of code, say <td align.... " +
rdr.getValue().ToString().Trim() + " >"
and then I simply write that to a text file named after the company.
Then basically the text file looks like the html code for a number of
tables. After that program finishes, I have it so that in the C# code
for my page it simply opens the file and reads the lines in 1 at a time
and stores them into the label like this :

temp = sr.ReadLine();
txt_summary += temp;

thanks for your reply and I'll look into the StringBuilder information.

Dan
 
DFDavis said:
Hans said:
This is probably a simple question, but I just started using C# and I
haven't done any projects like this before, however, I need to know if
there is a way to accomplish what I am currently doing in a faster
time. Right now I have a web page I created in VS 2005 where I am
pulling data from a database dependant upon who is logged in and
showing them the members and information for their specific company.
However, to display this on the web page I created a label and I simply
add the html code to that label. This seems to take a good 5 minutes
as some of the companies have 1200 some people and that means 3600
lines of html are added to this label. So basically is there a faster
way to take that code and add it to the page? Right now I have an
outside program create a file with the company name beforehand and this
file contains all the HTML I want to add. Sorry if this is confusing,
but I would greatly appreciate any help or ideas.

Thanks,

Dan

How are you building that HTML?
If you are using a string where you add each line to, then it is much
faster to use StringBuilder:

instead of:

string s = "";
for (int i=0; i<rows.Count; i++)
{
s = s + HtmlForRow(rows);
}
LabelOutput.Text = s;

use this:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i=0; i<rows.Count; i++)
{
sb.Append(HtmlForRow(rows));
}
LabelOutput.Text = sb.ToString();

see also http://www.yoda.arachsys.com/csharp/stringbuilder.html


Hans Kesting


Basically what I do is, go through with a reader from my query, then I
parse it into a line of code, say <td align.... " +
rdr.getValue().ToString().Trim() + " >"
and then I simply write that to a text file named after the company.
Then basically the text file looks like the html code for a number of
tables. After that program finishes, I have it so that in the C# code
for my page it simply opens the file and reads the lines in 1 at a time
and stores them into the label like this :

temp = sr.ReadLine();
txt_summary += temp;

thanks for your reply and I'll look into the StringBuilder information.

Dan


Just a quick update, the StringBuilder worked perfectly, thanks a lot.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top