Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:30am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

<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>
    
 
    <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>
    
 
    <asp:button id="btnMultiplication" runat="server" text="Multiplication" onclick="OnBtnMultiplicationClick" xmlns:asp="#unknown"></asp:button>
    
<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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 352
1 OriginalGriff 344
2 Abdul Samad KP 145
3 CPallini 140
4 Richard MacCutchan 110
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,680
2 CPallini 4,850
3 George Jonsson 3,454
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100