Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a web form that has a print button on it. When the user clicks the print button a report print out depending on the value. The user keeps getting the original report every time. Textbox1 = 40, Textbox2 = 50 and Textbox3 = 90.
Here is the code:
C#
int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
int iTextBoxHC50 = Convert.ToInt32(TextBoxHC50.Text);
int iTextBoxFTE4050 = Convert.ToInt32(TextBoxFTE4050);

if (iTextBoxFTE40 < 40)
{
   TextBoxINST_ID.Text = Session["inst_id"].ToString();
   ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
}
else if (iTextBoxFTE40 > 140)
{
   TextBoxINST_ID.Text = Session["inst_id"].ToString();
   ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE40.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
}
else if (iTextBoxHC50 > 150)
{
   TextBoxINST_ID.Text = Session["inst_id"].ToString();
   ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE50.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
}
else if (iTextBoxFTE4050 > 290)
{
   TextBoxINST_ID.Text = Session["inst_id"].ToString();
   ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
}


Is there a way to clean this up so it will work properly?
Posted
Updated 3-Nov-14 11:47am
v2
Comments
jkirkerx 30-Oct-14 16:37pm    
I would of wrote it in Javascript, in which when you click the print button, the javascript just gets the values and determines which page the user should be redirected to.

When I register a script, I just register 1, or how many are needed to complete all the tasks on the page.

Your design makes no sense to me, and seems to make things much more difficult than they need to be.
Computer Wiz99 3-Nov-14 9:09am    
I understand what you are saying but I don't know Javascript that well. The Values are also in the database. I populate them to three different textboxes. All I am trying to do is if textbox1 value is > 40 print page 1. If textbox2 value is > 50 print page 2. If textbox3 value is > 150 print page 3. I am trying to do this in C#.
jkirkerx 3-Nov-14 12:23pm    
How does the textbox gets its value?
Does the user input the value?
Or is the value a placeholder generated by the server?
Computer Wiz99 3-Nov-14 12:54pm    
The values come from a calculation that the user puts in earlier in the numbers that was entered. Then the values are saved into the database then then they are populated back to the textboxes for the print button to get the value from.

1 solution

I'm getting a feeling of deja vu ... i.e. we've been through this before.

In the debugger put a breakpoint on the line
C#
int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
and then start stepping through the code (usually F10/F11) and observe what happens.

First iTextBoxFTE40 is not less than 40 (Assuming TextBox1 is actually TextBoxFTE40) so processing will move on to the next if statement.

It's not greater than 140 either, so processing will move on to the next if statement...

Now assuming TextBox2 is TextBoxHC50 then it is equal to 50, which is not greater than 150, so ... processing moves on to the next if statement.

Finally assuming TextBox3 is TextBoxFTE4050 and equals 90, it is not greater than 290 so processing moves out of this code block all together.... without anything actually being assigned or actioned and that is why nothing changes each time this is run.

There are ways to clean this up but mainly you need rethink your overall logic.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900