Click here to Skip to main content
Sign Up to vote bad
good
See more: C#4.0
i have tow text boxes when i entered the values in the page the result should be displayed in the same page
Posted 4 Oct '12 - 7:30


3 solutions

double num1, num2;
private void button1_Click(object sender, EventArgs e)
{
    num1 = Convert.ToDouble(textBox1.Text);
    num2 = Convert.ToDouble(textBox2.Text);
    label1.Text = Convert.ToString(num1 * num2);
}
  Permalink  
Friend, on button click event, take the value of both text box like TextBox1.Text and convert them into double/int data type, multiply both the textbox values and assign the value on label as "Label1.Text =(Convert.ToInt(TextBox1.Text)*Convert.ToInt(TextBox2.Text)).ToString();"
 
Thanks,
Ambesha
  Permalink  
<body>
    <form id="form1" runat="server">
    <div>
    <asp:label id="lblNumber1" runat="server" text="Enter first value:" xmlns:asp="#unknown"></asp:label>
    <asp:textbox id="txtNumber1" runat="server" xmlns:asp="#unknown"></asp:textbox>
    <br />
    <asp:label id="lblNumber2" runat="server" text="Enter second value:" xmlns:asp="#unknown"></asp:label>
    <asp:textbox id="txtNumber2" runat="server" xmlns:asp="#unknown"></asp:textbox>
    <br />
    <asp:button id="btnMultiplication" runat="server" text="Multiplication" onclick="OnBtnMultiplicationClick" xmlns:asp="#unknown"></asp:button>
    <br /><asp:label id="lblMultiplication" runat="server" xmlns:asp="#unknown"></asp:label>
    </div>
    
    </form>
</body>
 
Now on code behind (test.aspx.cs):
----------------------------------
 protected void OnBtnMultiplicationClick(object sender, EventArgs e)
        {
            int num1=Convert.ToInt32(txtNumber1.Text);
            int num2 = Convert.ToInt32(txtNumber2.Text);
            lblMultiplication.Text = (num1 * num2).ToString();
 
        }
**Validation is not done so check for Null or empty value.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 325
1 Aarti Meswania 250
2 Sergey Alexandrovich Kryukov 249
3 Slacker007 240
4 Ron Beyer 190
0 Sergey Alexandrovich Kryukov 8,743
1 OriginalGriff 7,124
2 CPallini 3,678
3 Rohan Leuva 3,011
4 Maciej Los 2,403


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid