Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a web form that has a print button on it. The print button prints out a report from CRV. Right now the print button works fine for one report. I am trying to get it to print out a different report if the value in the textbox1 is a different number. Here is the code I have.

C#
protected void ButtonPrint_Click1(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim().Length > 0)
        {
            
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
        }

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

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

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


If the textbox has a value of 40 or more the report that matches 40 will print and the same with the rest. What is the best way to get the code to get the value of textbox1, textbox2, or textbox3 for the right report?
Posted
Updated 21-Oct-14 3:20am
v2
Comments
CHill60 12-Oct-14 9:53am    
Why are you checking the length of the text? Shouldn't you be checking the content??
Computer Wiz99 12-Oct-14 9:54am    
Okay. I think I see what is wrong now. It should be (TextBoxFTE4050.Text.Trim().Value < 40).
Computer Wiz99 12-Oct-14 9:59am    
That is not working. i changed it to (TextBoxFTE4050.Text.Trim().Value < 40) and get an error on the Value part.
CHill60 12-Oct-14 11:22am    
That's because string does not have a Value property. You need to use something like int.TryParse().
It seems a strange way to choose which report to run ... why not use a comboBox, dropdown list? What are you expecting in the textboxes - numbers?
You also appear to have a problem with the way the strings are created - quotes within a string need to be escaped
Computer Wiz99 12-Oct-14 23:56pm    
Sorry for the long wait but had to sleep. I am trying to get numbers in the textboxes and the value of them. I can't use comboBox or dropdown list. I do a calculation to get the numbers I need in the textbox in order to do the different printing.

1 solution

If you want to get value of TextBox, use Int32.TryParse method[^].

Rather than TextBox, use controls which enables you to make selection. See: HTMLControls and WebControls in ASP .NET[^]
 
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