Click here to Skip to main content
15,908,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web form that prints out different reports on different levels. All of the reports print out but not the report for the 40% and 50% change. I compound the IF statement and it still does not work. What did I do wrong?

C#
if (Page.IsValid)
                {
                    int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
                    int iTextBoxHC50 = Convert.ToInt32(TextBoxHC50.Text);
                    


                    if (iTextBoxFTE40 > 40)
                        if (iTextBoxHC50 > 50)
                    {
                        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>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }

                    else if (iTextBoxHC50 > 50)
                    {
                        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>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (iTextBoxFTE40 > 40)
                    {
                        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>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }
                    else 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>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }
Posted
Comments
Kornfeld Eliyahu Peter 12-Nov-14 9:52am    
You have twice iTextBoxHC50 > 50 - one of them should be iTextBoxHC50 < 50, me think...
Computer Wiz99 12-Nov-14 9:54am    
Yes I know. The first iTextBoxHC50 and iTextBoxFTE40 is a combined IF statement for one report and the other iTextBoxHC50 is a report by itself.
Computer Wiz99 12-Nov-14 9:55am    
There is one for the iTextBoxFTE40 for a report by itself.
Kornfeld Eliyahu Peter 12-Nov-14 10:01am    
This is your code without the actual printing
if ( Page.IsValid )
{
  int iTextBoxFTE40 = Convert.ToInt32( TextBoxFTE40.Text );
  int iTextBoxHC50 = Convert.ToInt32( TextBoxHC50.Text );

  if ( iTextBoxFTE40 > 40 )
    if ( iTextBoxHC50 > 50 )
    {
    }
    else if ( iTextBoxHC50 > 50 )
    {
    }
    else if ( iTextBoxFTE40 > 40 )
    {
    }
    else if ( iTextBoxFTE40 < 40 )
    {
    }
}
Computer Wiz99 12-Nov-14 10:02am    
Can I update my code to show you what I have changed? Please unlock it.

1 solution

For goodness sakes, sort out your indentation! :laugh:
It's easy enough to do - if your code compiles, then CTRL+K CTRL+D will do it.

But...you need to fix the compilation errors first.
Start with your strings:
C#
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language="javascript">window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");

Won't compile becasue teh "embedded" double quotes terminate the string. Try:
C#
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=\"javascript\">window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");


Then, you can format it, and it's clearer how VS will see the code:
C#
if (Page.IsValid)
    {
    int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
    int iTextBoxHC50 = Convert.ToInt32(TextBoxFTE50.Text);



    if (iTextBoxFTE40 > 40)
        if (iTextBoxHC50 > 50)
            {
            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>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }

        else if (iTextBoxHC50 > 50)
            {
            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>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }
        else if (iTextBoxFTE40 > 40)
            {
            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>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }
        else 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>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }

    }


So now, you can see what your "if"s are doing:
C#
if (Page.IsValid)
    {
    int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
    int iTextBoxHC50 = Convert.ToInt32(TextBoxFTE50.Text);
    if (iTextBoxFTE40 > 40)
        if (iTextBoxHC50 > 50)
            {
            }

        else if (iTextBoxHC50 > 50)
            {
            }
        else if (iTextBoxFTE40 > 40)
            {
            }
        else if (iTextBoxFTE40 < 40)
            {
            }
    }
And then it's obvious that that won't work!
The first "else if" is the same as the "if" condition above it!
 
Share this answer
 
Comments
[no name] 12-Nov-14 11:01am    
Special thanks for CTRL+K CTRL+D :-), my 5.

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