1. On Button Click Event
------------------------------
HTML PART
Untitled Page
Code Behind
----------------
protected void btnResult_Click(object sender, EventArgs e)
{
try
{
decimal result = Convert.ToDecimal(Convert.ToDecimal(txtPrice.Text) * Convert.ToInt32(txtQuantity.Text));
txtAmount.Text = Convert.ToString(result);
}
catch(Exception ex)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('Exception occur due to : {0}');", ex.Message), true);
}
}
2. On TextChanged Event
----------------------------
HTML Part
--------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Copy of Default.aspx.cs" Inherits="_Default" %>
Untitled Page
Code Behind
----------------
protected void txtQuantity_TextChanged(object sender, EventArgs e)
{
try
{
if (txtPrice.Text != String.Empty && txtQuantity.Text != string.Empty)
{
decimal result = Convert.ToDecimal(Convert.ToDecimal(txtPrice.Text) * Convert.ToInt32(txtQuantity.Text));
txtAmount.Text = Convert.ToString(result);
}
else
{
if (txtPrice.Text == String.Empty)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('Please enter price');"), true);
}
if (txtQuantity.Text == String.Empty)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('Please enter quantity');"), true);
}
}
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('Exception occur due to : {0}');", ex.Message), true);
}
}
protected void txtPrice_TextChanged(object sender, EventArgs e)
{
try
{
if (txtPrice.Text != String.Empty && txtQuantity.Text != string.Empty)
{
decimal result = Convert.ToDecimal(Convert.ToDecimal(txtPrice.Text) * Convert.ToInt32(txtQuantity.Text));
txtAmount.Text = Convert.ToString(result);
}
else
{
if (txtPrice.Text == String.Empty)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('Please enter price');"), true);
}
if (txtQuantity.Text == String.Empty)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('Please enter quantity');"), true);
}
}
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", string.Format("alert('Exception occur due to : {0}');", ex.Message), true);
}
}
3. By Using Javascript
------------------------
HTML Part (With Javascript)
------------------------------------
Untitled Page