Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:10:34+00:00 2026-06-17T06:10:34+00:00

In Asp.net using c# ,I am having int sum = Convert.ToInt32(txtbox1.Text) + Convert.ToInt32(txtbox2.Text); When

  • 0

In Asp.net using c# ,I am having

int sum = Convert.ToInt32(txtbox1.Text) + Convert.ToInt32(txtbox2.Text);

When i have an empty textbox, i get the error “Input string is not in a correct format”.

So, I am wondering if there is a simple way to add textbox values only they are integers, if not take the textbox value as 0.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:10:35+00:00Added an answer on June 17, 2026 at 6:10 am

    You can either set the default value of the TextBox to 0, or use TryParse:

    int val1, val2;
    Int.TryParse(txtbox1.Text,out val1));
    Int.TryParse(txtbox2.Text,out val2));
    int sum =  val1 + val2;
    

    Note that you do not need to set the values to 0 if the parse fails since they will be 0 anyways. If you want to be explicit, however:

    int val1, val2;
    if(!Int.TryParse(txtbox1.Text,out val1))) val1 = 0;
    if(!Int.TryParse(txtbox2.Text,out val2))) val2 = 0;
    int sum =  val1 + val2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a really frustrating error trying to secure an ASP.NET application using the
I'm using ASP.NET MVC + NHibernate + Fluent NHibernate and having a problem with
I am using ASP.NET Web Forms/C# . I am having this function in my
I am currently using ASP.NET MVC 2.0 RC2, having recently moved from version 1.0.
I am having an issue with a website developed using ASP.Net/C# sometimes taking all
I am having a weird issue in MVC. I am using ASP.Net MVC, I
I'm using KnockoutJS with ASP.NET MVC, and I'm having a problem with broken bindings
We're going through an ASP.Net MVC book and are having trouble with using an
I am working on asp.net using c#. I have one master page with 3
I have created an Asp.net website using VS 2008 and SQL Express 2008 on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.