help, my program runs to fast!

A

André

Hi,

I made a webform for a survey, with multiple-choice questions. The results
of each question is put into a table e.g.:
values frequency
1 6
2 3
3 32
4 26
5 12

Now i want to add a graphic beside the table representing those values. So i
use two files, the second containing the code for the graphic.
I tried two ways: with a cookie and with passing a parameter. Everything
works, except that the second file has no time to create and render the
graphic.

When using a cookie, all graphics are rendered in file 1 but all with the
values of the last question.
When using a parameter, only the graphic of the last question is rendered
(with the right values).

Do you know a way to 'slow down' file1, so file2 has enough time to produce
and send the graphic to file 1? Or any other solution?

Thanks
André




My code:

file1: (with parameter)
-----
'valtopass is the string containing the values to pass with ':' as separator
(e.g. 6:3:32:26:12)
....
For j = 1 To numberoffield
'create table
....
gr.ImageUrl = "graf2.aspx?v1=" & valtopass
form1.Controls.Add(gr)
next
....

file1: (with cookie)
-----
'valtopass is the string containing the values to pass with ':' as separator
(e.g. 6:3:32:26:12)
'cok = HttpCookie
....
For j = 1 To numberoffield
'create table
....
cok.value=valtopass
response.cookies.add(cok)
next
....
 
M

Mark Rae

Or any other solution?

Don't take this the wrong way, but you really should get hold of a
beginner's guide to ASP.NET and work your way through it. You mentioned in a
previous post that you are a newbie - which is fine, we were all newbies
once - but you are getting yourself into horrible tangles here trying to
accomplish something which is, in fact, incredibly simple if you just use
ASP.NET properly.

For one thing, you don't need two files for this. You say you want to
display some records out of a datatable textually and graphically - well use
a DataGrid or a Repeater - that's what these controls are for.

And secondly, and far more importantly, you really must get out of the habit
of using cookies to persist state across aspx pages - that isn't what
they're for at all. You might also be surprised to know how many people have
their browser configured not to accept cookies by default...
 
A

André

Thanks anyway for replying ...
What i have done is programmatically create a form with radiobuton,
dropdownlist etc ...for any kind of survey. The program reads from an excel
sheet the questions and type of questions (open, not open, min/max values
etc ..) and in function of all those parameters, the program create a
inputform. The program then calculate the statistics and show them in tables
(one per question). I do use datereader and tables.
This part works great, but what i would like to do is beside each table,
create a little 2-D bitmap graphic representing the frequenties. So to my
knowledge (and according others experts in this group), that bitmap graphic
must be created in another page and called from the first page. This also
works great (with one table and one graphic), except when there are a lot of
graphics to make (one per question).

So, please Mark, don't think i'm a fool who can nearly read or something. I
have a actual problem: how to get those bitmap graphics beside each table
into page 1? Is this problem so weird, so stupid or ridiculus? Not to me
anyway.
I would very much appreciate if you could help me. About the cookie, i agree
with you. I hope you noticed I tried another solution with sending a
parameter. But that doesn't work, so i try something else with cookies. Is
there more, better solutions? Tell me then. Please
 
M

Mark Rae

This part works great, but what i would like to do is beside each table,
create a little 2-D bitmap graphic representing the frequenties. So to my
knowledge (and according others experts in this group), that bitmap
graphic must be created in another page and called from the first page.
This also works great (with one table and one graphic), except when there
are a lot of graphics to make (one per question).

Well, I don't know who told you that - there is absolutely no need to use
two pages for this.
So, please Mark, don't think i'm a fool who can nearly read or something.
I have a actual problem: how to get those bitmap graphics beside each
table into page 1? Is this problem so weird, so stupid or ridiculus? Not
to me anyway.

Don't shoot the messenger, mate... The problem isn't weird, stupid or
ridiculous - you've obviously been given bad advice.
I would very much appreciate if you could help me.

Here's a quick and dirty page I knocked up in about five minutes - no need
for messing about with bitmap graphics or whatever...
I hope this is the sort of thing you're looking for (code is below).
Obviously, I have hard-coded the data and you will be fetching it from a
database, but the concept is the same.

http://www.markrae.com/zzScratch/TestBars.aspx
About the cookie, i agree with you. I hope you noticed I tried another
solution with sending a parameter. But that doesn't work, so i try
something else with cookies. Is there more, better solutions? Tell me
then. Please

Are you not, then, fetching the data from a database? In which case, you
don't actually need to pass anything anywhere - just read it when you need
it...

However, in ASP.NET if you need to persist data across more than one page,
you have several choices:

1) you can append the data to the target URL in a querystring e.g.
test.aspx?id=1&value=2

2) you can use the Session object to store the value(s)

3) in ASP.NET 2, you can post from one page to another



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestBars.aspx.cs"
Inherits="zzScratch_TestBars" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Dynamically sized graphics</title>
</head>

<body>
<form id="form1" runat="server">
Change the values in the boxes and click here <asp:Button ID="cmdRedraw"
runat="server" Text="Redraw" OnClick="cmdRedraw_Click" /><br />
<br />
<asp:Table ID="tblBars" runat="server">
<asp:TableHeaderRow>
<asp:TableHeaderCell Text="Value" HorizontalAlign="Left" />
<asp:TableHeaderCell Text="Frequency" HorizontalAlign="Left" />
<asp:TableHeaderCell Text="Graphic" HorizontalAlign="Left" />
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell Text="1" />
<asp:TableCell><asp:TextBox runat="server" Text="6" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="60px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="2" />
<asp:TableCell><asp:TextBox runat="server" Text="3" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="30px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="3" />
<asp:TableCell><asp:TextBox runat="server" Text="32" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="320px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="4" />
<asp:TableCell><asp:TextBox runat="server" Text="26" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="260px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="5" />
<asp:TableCell><asp:TextBox runat="server" Text="12" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="120px"
/></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>



using System;
using System.Web.UI.WebControls;

public partial class zzScratch_TestBars : System.Web.UI.Page
{
protected void cmdRedraw_Click(object sender, EventArgs e)
{
foreach (TableRow objTR in tblBars.Rows)
{
if (objTR.GetType().Name == "TableRow")
{
((Label)objTR.Cells[2].Controls[0]).Width =
Unit.Pixel(Convert.ToInt32(((TextBox)objTR.Cells[1].Controls[0]).Text) *
10);
}
}
}
}
 
A

André

I admit that your solution is easier than working with bitmap graphics, but
you must admit that this graphic is very simple. With the
'System.Drawing.Imaging ' namespace, you can do a lot more (pie, lines etc
...), and in that case, you need two files (see another of my threads "how to
render a graphic ..." frm 27/11 and the answer of Steve Orr (MCSD, MVP, CSM,
ASPInsider).
So, if i can't find a solution on my problem, i will use yours.
The data in the database are the values inputted by people who answered the
question. So the program first calculate all statistics, and those values,
for each question, must be passed to the graphic.

But i still wonder why only the last graphic is rendered back to page 1. I
can't see any bug in my code, nor a logical error. A matter of speed, i
thing: the tag <img ...?....> referning and passing the right data to the
graphic, then the creation of the graphic and back to the file 1 takes too
long. During that operation, the loop between all questions goes further,
passing new data to the file 2.

Anyway, thanks for your advices and time





Mark Rae said:
This part works great, but what i would like to do is beside each table,
create a little 2-D bitmap graphic representing the frequenties. So to my
knowledge (and according others experts in this group), that bitmap
graphic must be created in another page and called from the first page.
This also works great (with one table and one graphic), except when there
are a lot of graphics to make (one per question).

Well, I don't know who told you that - there is absolutely no need to use
two pages for this.
So, please Mark, don't think i'm a fool who can nearly read or something.
I have a actual problem: how to get those bitmap graphics beside each
table into page 1? Is this problem so weird, so stupid or ridiculus? Not
to me anyway.

Don't shoot the messenger, mate... The problem isn't weird, stupid or
ridiculous - you've obviously been given bad advice.
I would very much appreciate if you could help me.

Here's a quick and dirty page I knocked up in about five minutes - no need
for messing about with bitmap graphics or whatever...
I hope this is the sort of thing you're looking for (code is below).
Obviously, I have hard-coded the data and you will be fetching it from a
database, but the concept is the same.

http://www.markrae.com/zzScratch/TestBars.aspx
About the cookie, i agree with you. I hope you noticed I tried another
solution with sending a parameter. But that doesn't work, so i try
something else with cookies. Is there more, better solutions? Tell me
then. Please

Are you not, then, fetching the data from a database? In which case, you
don't actually need to pass anything anywhere - just read it when you need
it...

However, in ASP.NET if you need to persist data across more than one page,
you have several choices:

1) you can append the data to the target URL in a querystring e.g.
test.aspx?id=1&value=2

2) you can use the Session object to store the value(s)

3) in ASP.NET 2, you can post from one page to another



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestBars.aspx.cs"
Inherits="zzScratch_TestBars" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Dynamically sized graphics</title>
</head>

<body>
<form id="form1" runat="server">
Change the values in the boxes and click here <asp:Button ID="cmdRedraw"
runat="server" Text="Redraw" OnClick="cmdRedraw_Click" /><br />
<br />
<asp:Table ID="tblBars" runat="server">
<asp:TableHeaderRow>
<asp:TableHeaderCell Text="Value" HorizontalAlign="Left" />
<asp:TableHeaderCell Text="Frequency" HorizontalAlign="Left" />
<asp:TableHeaderCell Text="Graphic" HorizontalAlign="Left" />
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell Text="1" />
<asp:TableCell><asp:TextBox runat="server" Text="6" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="60px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="2" />
<asp:TableCell><asp:TextBox runat="server" Text="3" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="30px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="3" />
<asp:TableCell><asp:TextBox runat="server" Text="32" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="320px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="4" />
<asp:TableCell><asp:TextBox runat="server" Text="26" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="260px"
/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="5" />
<asp:TableCell><asp:TextBox runat="server" Text="12" Width="20px"
MaxLength="2" /></asp:TableCell>
<asp:TableCell><asp:Label runat="server" BackColor="Red" Width="120px"
/></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>



using System;
using System.Web.UI.WebControls;

public partial class zzScratch_TestBars : System.Web.UI.Page
{
protected void cmdRedraw_Click(object sender, EventArgs e)
{
foreach (TableRow objTR in tblBars.Rows)
{
if (objTR.GetType().Name == "TableRow")
{
((Label)objTR.Cells[2].Controls[0]).Width =
Unit.Pixel(Convert.ToInt32(((TextBox)objTR.Cells[1].Controls[0]).Text) *
10);
}
}
}
}
 
M

Mark Rae

I admit that your solution is easier than working with bitmap graphics, but
you must admit that this graphic is very simple.

It certainly is.
With the 'System.Drawing.Imaging ' namespace, you can do a lot more (pie,
lines etc ..), and in that case, you need two files (see another of my
threads "how to render a graphic ..." frm 27/11 and the answer of Steve
Orr (MCSD, MVP, CSM, ASPInsider).

OK.
 
A

André

So, if i want some more sophisticated graphic for each question, i must use
the 'System.Drawing.Imaging' and so i'm back to the starting point: how to
get beside each table the appropriate graphic or why do i only get the
graphic of the last question?

But i thing you spend enough time to me, so i'll repost it and reformulate
it more clearly.
Thanks
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top