Hi to All,

I am accessing text box value and error is operator '-' cannot be applied to operands of type System.web.UI.WebControls.TextBox and int

Recommended Answers

All 3 Replies

Are you accessing the ToString() property of the textbox? If not, you're not working with the string value itself, you're trying to alter the TextBox control. Are you trying to subtract two numbers or are you working with text input?

Can you elaborate your problem as to exactly what you are trying to do

Here is an example:

private void button6_Click(object sender, EventArgs e)
    {
      int i1;
      int i2;
      if (int.TryParse(textBox1.Text, out i1) && int.TryParse(textBox2.Text, out i2))
      {
        int sum = i1+i2;
        textBox3.Text = "The sum is " + sum.ToString();
      }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.