need code for TEXTCHANGED EVENT

Posted by Parthibansk under ASP.NET on 12/6/2012 | Points: 10 | Views : 1425 | Status : [Member] | Replies : 3
GOT THREE TEXTBOX. UNITS | COST |TOTAL

I WANT 2 DISPLAY TOTAL ON TEXT CHANGED EVENT OF TEXTBOX..

/* decimal totalcost;

totalcost = (Convert.ToDecimal(textboxunit.Text)) * (Convert.ToDecimal(textboxCost.Text)); */




Responses

Posted by: Ranjeet_8 on: 12/6/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Add this on .Aspx Design page

<asp:TextBox ID="textboxunit" runat="server" OnTextChanged="textboxunit_TextChanged"
AutoPostBack="True"></asp:TextBox>
<asp:TextBox ID="textboxCost" runat="server" OnTextChanged="textboxunit_TextChanged"
AutoPostBack="True"></asp:TextBox>
<asp:TextBox ID="texttotal" runat="server"></asp:TextBox>

Add this on .CS Page

protected void textboxunit_TextChanged(object sender, EventArgs e)
{
try
{
if (textboxunit.Text.Trim() != "" && textboxCost.Text.Trim() != "")
texttotal.Text = String.Format("{0:0.00}", (Convert.ToDouble(textboxunit.Text)) * (Convert.ToDouble(textboxCost.Text)));
textboxCost.Focus();
}
catch { }
}


Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 12/6/2012 [Member] Bronze | Points: 25

Up
0
Down
<table id="cc" cellpadding="2" cellspacing="2" width="200">
<tr>
<td>
UNITS
</td>
<td>
<asp:TextBox ID="txtunits" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
COST
</td>
<td>
<asp:TextBox ID="txtCost" runat="server" ontextchanged="txtCost_TextChanged" AutoPostBack="true" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
TOTAL
</td>
<td>
<asp:TextBox ID="txttotal" runat="server" ></asp:TextBox>
</td>
</tr>
</table>

protected void txtCost_TextChanged(object sender, EventArgs e)
{
txttotal.Text = (Convert.ToDecimal(txtunits.Text) * Convert.ToDecimal(txtCost.Text)).ToString();
}

Thanks
Pavan Kumar
Mark Answer if this fits the need

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 12/6/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi @Parthibansk
plz Mark As Answer if post will helps you.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response