Click here to Skip to main content
15,921,959 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have tow text boxes when i entered the values in the page the result should be displayed in the same page
Posted

C#
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);
}
 
Share this answer
 
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
 
Share this answer
 
C#
<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):
----------------------------------
C#
 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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900