Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a web form that has three textboxes on it. Each textbox will have a different value in it. With that value there are four different reports I want to print out for each different value. If textbox1 has a value of 40 then the report matching 40 will print out. If textbox2 has a value of 50 then the report that matches 50 will print out and so on. When the user clicks the print button the first and original report prints. What did I do wrong in my code to get this error?

C#
protected void ButtonPrint_Click1(object sender, EventArgs e)
    {
        int iTextBoxValue = Convert.ToInt32(TextBox1.Text);
        int iTextBoxValue1 = Convert.ToInt32(TextBox2.Text);
        int iTextBoxValue2 = Convert.ToInt32(TextBox3.Text);
        int iTextBoxValue3 = Convert.ToInt32(TextBox4.Text);

        if (iTextBoxValue > 90)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
        }

        else if (iTextBoxValue1 < 40)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE40.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
        }

        else if (iTextBoxValue2 < 50)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE50.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
        }

        else if (iTextBoxValue3 < 90)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
        }
    }
Posted
Updated 21-Oct-14 4:26am
v2
Comments
CHill60 21-Oct-14 10:04am    
What is the value of iTextBoxValue0? And if textBox1 has a value of 40 then the report matching 50 will print out based on this code.
As you've been told before, this is the wrong way to go about this - use something that allows you to make a choice, not different controls
Computer Wiz99 21-Oct-14 10:25am    
What I have on the web form should not give a user a choice. When the user enters their data and the calculations are done, the validators are fired if the users calculation is more than what was inputted then last year. If a user's data from last year was 100 and this year they enter 121. This will fire the vaidator because it is a 20% increase from last year. Which will then let the user print a report because of this value. What other way can this be done?
CHill60 21-Oct-14 10:31am    
"fire the validator... 20% increase" these comments have nothing to do with this question on ButtonPrint. The report chosen is based upon the content of those text boxes - how do they get populated and why do you have 4 of them?
Computer Wiz99 21-Oct-14 10:44am    
Textbox has a value of 0 which should print out the original report
Textbox2 has a value of 40 which should print out the 40 report
Textbox3 has a value of 50 which should print out the 50 report
Textbox4 has a value of 90 which should print out the 90 report

Textbox4 has the sum of textbox2 and textbox3. The reports lets the user know that they will have to explain why this is so. If the report is normal then the user will not have to explain. What is the best way to do this?
CHill60 21-Oct-14 10:50am    
Which value does Textbox2 have when you have your problem - you've listed 3 different values here - it can only have one!

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