Click here to Skip to main content
15,908,674 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 four different reports depending on the value of the three textboxes.

Here is the Print button code:
C#
if (Page.IsValid)
               {
                   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('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 (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 (iTextBoxFTE4050 > 90)
                   {
                       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
                   {
                       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);
                   }


When the Print button is clicked this error comes up:
HTML
Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'.

What does this mean? It happens on this line:
C#
int iTextBoxFTE4050 = Convert.ToInt32(TextBoxFTE4050);


How can I fix this?
Posted

1 solution

If you'd bothered to read Chill60's answer[^] to your previous copy of this question[^], you'd know the answer:
C#
int iTextBoxFTE4050 = Convert.ToInt32(TextBoxFTE4050.Text);
 
Share this answer
 
Comments
Computer Wiz99 4-Nov-14 13:24pm    
I did that and still getting this error. It only happens on this line of code. Plus, that was not my question before. I asked about something else. Not about this new error.
Richard Deeming 4-Nov-14 13:27pm    
No, if you're getting the same error (Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'), then you haven't added the missing .Text property access on the affected line. You're still trying to pass the TextBox itself to the Convert.ToInt32 method.

It's quite possible you'll still get an error if the text isn't a valid number. But you won't get the same error that you posted in your question.
Computer Wiz99 4-Nov-14 13:32pm    
That is all I was missing. This was not a double question. Just need some fresh eyes on it to see what I did wrong or missed. Thanks.

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