Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want calculate total amount when user enters quantity in textbox..it works when postback occurs but i want to do it dynamically without postback..is there any another solution plz tell me.

//source code
XML
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                    <ContentTemplate>
                                   <asp:TextBox ID="TxtATQuantityATC"  runat="server" AutoPostBack="true" OnTextChanged="TxtATQuantityATC_TextChanged" ></asp:TextBox>
                                </ContentTemplate>
                                <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="TxtATQuantityATC" EventName="TextChanged" />

                                </Triggers>
                               </asp:UpdatePanel>


//.cs

C#
protected void TxtATQuantityATC_TextChanged(object sender, EventArgs e)
   {

      
       int Price = int.Parse(LblATUPriceATC.Text);
       int Quantity = int.Parse(TxtATQuantityATC.Text);
       int TotalPrice = Quantity * Price;
       LblATTotalAmntATC.Text = TotalPrice.ToString();
     
       MpeAddToCart.Show();

   }
Posted
Comments
[no name] 16-Feb-13 4:30am    
no without postback you don't do that
else use javascript function!!!!
Member 9579525 16-Feb-13 4:34am    
thank u..can u suggest me which functon and how to use it??

1 solution

JavaScript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("#txtQuantity").blur(function(){
      var price = $("#lblPrice").text();
      var totalAmount = $("#lblTotal");
      var toal = parseFloat(this.value) * parseFloat(price);
      totalAmount.text(total);
  });
});
</script>

ASP.NET
Quantity: <asp:TextBox id="txtQuantity" runat="server" />
<br />
Price: <asp:Label id="lblPrice" runat="server" Text="10" />
<br />
Total Amount: <asp:Label id="lblTotal" runat="server" />
<br />
 
Share this answer
 
v4
Comments
Member 9579525 16-Feb-13 4:39am    
thank u... my unit price is on label and want to diaplay total price on another label so will it work using above code.
Bandi Ramesh 16-Feb-13 4:51am    
Verify my modified example; hope it helps you.
Member 9579525 16-Feb-13 5:32am    
Thanks...I have done same but its not working..any other way?
Bandi Ramesh 16-Feb-13 5:36am    
can you post your code here? that will help us point out the issue...
Member 9579525 16-Feb-13 5:57am    
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#txtQuantity").blur(function(){
var price = $("#LblATUPriceATC").text();
var totalAmount = $("#TxtATQuantityATC");
var toal = parseFloat(this.value) * parseFloat(price);
totalAmount.text(total);
});
});
</script>


<asp:Button CssClass="inputcommon" ID="BtnATAddToCart" runat="server" Text="Add To Cart" onclick="BtnATAddToCart_Click" />
<asp:Button ID="BtnATHidden" style="display:none" runat="server" Text="Button" />

<cc1:ModalPopupExtender ID="MpeAddToCart" runat="server" TargetControlID="BtnATHidden" PopupControlID="PanelAddToCart" >




<asp:Panel ID="PanelAddToCart" runat="server">

<div style="text-align:right; margin-bottom:-15px; margin-right:-10px;">
<asp:ImageButton ID="ImgbtnATCancelATC" OnClick="ImgbtnATCancelATC_Click"
ImageUrl="~/System Modules/Standard/images/close.png" style="width:30px; height:30px;" runat="server" />
</div>

<div style="color:Black; color:#fff; background-color:#400a0a;
border-width:2px; border:5px solid silver; padding: 10px; font-size:14px; text-align:left;">



<table cellspacing="15">
<tr>
<td>
Currency Type:
</td>
<td>
<asp:RadioButton ID="RdoATbtnINRATC" Text="INR" runat="server" AutoPostBack="true" OnCheckedChanged="RdoATbtnINRATC_CheckedChanged" GroupName="PRICE" />

</td>
<td>
<asp:RadioButton ID="RdoATbtnDOLLARATC" Text="$" runat="server" AutoPostBack="true" OnCheckedChanged="RdoATbtnDOLLARATC_CheckedChanged" GroupName="PRICE" />
</td>
<td>
<asp:RadioButton ID="RdoATbtnEUROATC" Text="EURO" runat="server" AutoPostBack="true" OnCheckedChanged="RdoATbtnEUROATC_CheckedChanged" GroupName="PRICE" />
</td>
</tr>
<tr>
<td>
Unit Price:
</td>
<td colspan="3">
<asp:Label ID="LblATUPriceATC" runat="server" >
</td>
</tr>
<tr>
<td>
Items Required:
</td>
<td colspan="3">

<asp:TextBox ID="TxtATQuantityATC" runat="server" >

</td>

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