casting, converting, and input from textbox controls

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-06-16T02:23:51Z Indexed on 2010/06/16 2:32 UTC
Read the original article Hit count: 299

Filed under:
|

Working on some .aspx.cs code and decided I would forget how to turn a textbox value into a useable integer or decimal. Be warned I'm pretty new to .asp. Wish I could say the same for c sharp. So the value going into my textbox (strawberryp_textbox) is "1" which I presume I can access with the .text property. Which I then parse into a int. The Error reads Format Exception was unhandled by user code.

My other question is can I do operations on a session variable?

protected void submit_order_button_Click(object sender, EventArgs e)
{
    int strawberryp;
    int strawberrys;

    decimal money1 = decimal.Parse(moneybox1.Text);
    decimal money2 = decimal.Parse(moneybox2.Text);
    decimal money3 = decimal.Parse(moneybox3.Text);
    decimal money4 = decimal.Parse(moneybox4.Text);
    decimal money5 = decimal.Parse(moneybox5.Text);

    strawberryp = int.Parse(strawberryp_Textbox.Text);    //THE PROBLEM RIGHT HERE!
    strawberrys = int.Parse(strawberrys_Textbox.Text); // Needs fixed
    int strawberryc = int.Parse(strawberryc_Textbox.Text); //fix
    int berryp = int.Parse(berryp_Textbox.Text); //fix
    int raspberryp = int.Parse(raspberryp_Textbox.Text); /fix
    decimal subtotal = (money1 * strawberryp) + (money2 * strawberrys) + (money3 * strawberryc) + (money4 * berryp) + (money5 * raspberryp); //check to see if you can multiply decimal and int to get a deciaml!!


    Session["passmysubtotal"] = subtotal; //TextBox2.Text;

    (strawberryp_Textbox.Text);//TextBox4.Text;

    add_my_order_button.Enabled = true;
    add_my_order_button.Visible = true;
    submit_order_button.Enabled = false;
    submit_order_button.Visible = false;
    strawberryp_Textbox.ReadOnly = false;
    strawberrys_Textbox.ReadOnly = false;
    strawberryc_Textbox.ReadOnly = false;
    berryp_Textbox.ReadOnly = false;
    raspberryp_Textbox.ReadOnly = false;
    Response.Redirect("reciept.aspx");
}

Thanks for the help

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET