954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# code to form a calculator in asp.net

please help me with the code behind file..as i am really confused...otherwise give me some tips to start doing the code

priyad2
Newbie Poster
3 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Hi
use array of button to make calculator then assign code on button click, on the base of index process the request.

if you are not stick to server side programming you can use javaScript also to make nice calculator.

DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 
please help me with the code behind file..as i am really confused...otherwise give me some tips to start doing the code

This is code for display calculator in asp.net

First use name spaceusing System.Diagnostics;

with in button write down this code

Button1(.................)
{
Process p=new Process();
p.startInfo.FileName="calc";
p.start();
}

sunilcnpd
Newbie Poster
1 post since May 2009
Reputation Points: 10
Solved Threads: 0
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        bool plus = false;
        bool minus = false;
        bool multiply = false;
        bool divide = false;
        public Form1()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            
            calci.Text = calci.Text + "1";
            
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "2";
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "3";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "4";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "5";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "6";
        }

        private void button7_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "7";

        }

        private void button8_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "8";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            calci.Text = calci.Text + "9";
        }

        private void button10_Click(object sender, EventArgs e)
        {
                calci.Text = calci.Text + "0";
           
        }


        private void button16_Click(object sender, EventArgs e)
        {
            calci.Text = "";
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (calci.Text == "")
            {
                return;
            }
            else
            {
                plus = true;
                calci.Tag = calci.Text;
                calci.Text = "";
            }
           
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (plus)
            {
                    decimal dec = Convert.ToDecimal(calci.Tag) + Convert.ToDecimal(calci.Text);
                    calci.Text = dec.ToString();
            }
            else if (minus)
            {
                    decimal dec = Convert.ToDecimal(calci.Tag) - Convert.ToDecimal(calci.Text);
                    calci.Text = dec.ToString();
            }
            else if (multiply)
            {
                     decimal dec = Convert.ToDecimal(calci.Tag) * Convert.ToDecimal(calci.Text);
                     calci.Text = dec.ToString();
            }
            else if (divide)
            {
                      decimal dec = Convert.ToDecimal(calci.Tag) / Convert.ToDecimal(calci.Text);
                      calci.Text = dec.ToString();
            }
            return;
        }

                

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button17_Click(object sender, EventArgs e)
        {
            if (calci.Text.Contains("."))
            {
                return;
            }
            else
            {
                calci.Text = calci.Text + ".";
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (calci.Text == "")
            {
                return;
            }
            else
            {
                minus = true;
                calci.Tag = calci.Text;
                calci.Text = "";
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (calci.Text == "")
            {
                return;
            }
            else
            {
                multiply = true;
                calci.Tag = calci.Text;
                calci.Text = "";
            }
        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (calci.Text == "")
            {
                return;
            }
            else
            {
                divide = true;
                calci.Tag = calci.Text;
                calci.Text = "";
            }
        }
    }
}
manjunathgc
Newbie Poster
1 post since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

Perhaps a look at this thread and the links you find in it could help?

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

what is "tag" in this code..??
please reply soon.........

uzma sattar
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This Code is Best in all codes

use these html code in aspx page

>>>>>

<FORM NAME="Calc">
<TABLE BORDER=4>
<TR>
<TD>
<INPUT TYPE="text"   NAME="Input" Size="16">

</TD>
</TR>
<TR>
<TD>
<INPUT TYPE="button" NAME="one"   VALUE="  1  " OnClick="Calc.Input.value += '1'">
<INPUT TYPE="button" NAME="two"   VALUE="  2  " OnCLick="Calc.Input.value += '2'">
<INPUT TYPE="button" NAME="three" VALUE="  3  " OnClick="Calc.Input.value += '3'">
<INPUT TYPE="button" NAME="plus"  VALUE="  +  " OnClick="Calc.Input.value += ' + '">

<INPUT TYPE="button" NAME="four"  VALUE="  4  " OnClick="Calc.Input.value += '4'">
<INPUT TYPE="button" NAME="five"  VALUE="  5  " OnCLick="Calc.Input.value += '5'">
<INPUT TYPE="button" NAME="six"   VALUE="  6  " OnClick="Calc.Input.value += '6'">
<INPUT TYPE="button" NAME="minus" VALUE="  -  " OnClick="Calc.Input.value += ' - '">

<INPUT TYPE="button" NAME="seven" VALUE="  7  " OnClick="Calc.Input.value += '7'">
<INPUT TYPE="button" NAME="eight" VALUE="  8  " OnCLick="Calc.Input.value += '8'">
<INPUT TYPE="button" NAME="nine"  VALUE="  9  " OnClick="Calc.Input.value += '9'">
<INPUT TYPE="button" NAME="times" VALUE="  x  " OnClick="Calc.Input.value += ' * '">

<INPUT TYPE="button" NAME="clear" VALUE="  c  " OnClick="Calc.Input.value = ''">
<INPUT TYPE="button" NAME="zero"  VALUE="  0  " OnClick="Calc.Input.value += '0'">
<INPUT TYPE="button" NAME="DoIt"  VALUE="  =  " OnClick="Calc.Input.value = eval(Calc.Input.value)">
<INPUT TYPE="button" NAME="div"   VALUE="  /  " OnClick="Calc.Input.value += ' / '">

</TD>
</TR>
</TABLE>
</FORM>

<p align="center"><font face="arial" size="-2">This free script provided by</font>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>

Thanks
Islam is the Best

hassan12345
Light Poster
42 posts since Aug 2010
Reputation Points: 10
Solved Threads: 3
 

Well congratulations everybody on just handing out code to someone. My particular favorite was this one:

Button1(.................)
{
Process p=new Process();
p.startInfo.FileName="calc";
p.start();
}


That being said... when someone comes to the forum and says "please help me with the code behind file..as i am really confused...otherwise give me some tips to start doing the code" do you think that they benefit more from having completed code snippets dropped in their lap or from being told how to go about coding the application they're working on?

DangerDev and ddanbe good on you two for pointing the user in the right direction :twisted: At least some folks are still following the 'developmental learning' model around here as opposed to the 'here's a free hand out, go turn it in to your teacher' model.

Now as to the original question, similar to ddanbe I'm going to provide a reference to another thread . Perhaps the information in that thread will help you sort out your calculator code issue.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 

@Lusiphur this is not code its just cheating :p

hassan12345
Light Poster
42 posts since Aug 2010
Reputation Points: 10
Solved Threads: 3
 

Hi hassan12345
I have created the calculator already with the codes in aspx page,
my problem is how to get this calculator get going. . pls help me =)
I need the codes for the aspx.cs page
thank you

aizalee
Newbie Poster
1 post since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

dear aizalee it just a html and javascript code you can use it any code like asp,php,jsp etc
and i already test it it give you gui with best calculation result !!

hassan12345
Light Poster
42 posts since Aug 2010
Reputation Points: 10
Solved Threads: 3
 

aizalee i check your code and remove your error
check above link and download code and enjoy it
http://www.4shared.com/file/Od1IHKAa/Asp_Calculater_with_masterPage.html

hassan12345
Light Poster
42 posts since Aug 2010
Reputation Points: 10
Solved Threads: 3
 

Down load full source code for making EMI calculator in c#

http://www.authorcode.com/how-to-make-emi-calculator-using-c/

hscoder
Newbie Poster
6 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Infraction Points: 5
 

Really? You think the original poster is still looking for code after 3 years?

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

@ Lusiphur: I am a beginner as well and I am also learning c# by myself now. I have a book on ASP.Net 3.5 and Silverlight 3 as well. i really think that these guys that have typed out the code and posted it on here help out a lot. Beginners like myself like that people like these guys and gals are willing to post up their code on here. We "noobs" (if you will) like to learn from the professionals because we do need help. I needed help on a Yahtzee game in c++ a while back and a couple of guys and gals really helped me out. They made some code for me and I intertwined it into my code. They helped me with resizing the screen and a little bit of the scoring function. When you have completed code like this, I myself can understand what's going on and try to fill in the gaps myself; if not at least make some adjustments from their code and maybe re-write their same code over so I can have it in my head. We like to use references when we are in school and I love it when others see that we really do want to learn. So Thank You all that have ever posted up code as well as complete code in these forums. God Bless All of You and Your Families As Well.

Zvjezdan23
Junior Poster
154 posts since Dec 2010
Reputation Points: -3
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You