Update Price Value in TextBox based on value

I have 2 text boxes the default value for TextBox1 is "1" this is the amount to be ordered. In the other textbox, TextBox2 the value is the price (taken from the database).

If for example the site visitor changes the value in textbox1 to "3" then the price value in TextBox2 will be multiplied by 3 and displayed.

I'm not sure how best to accomplish this. I have tried "OnTextChanged" but to be honest I'm a bit lost. Code needs to be in C#

The page allows purchase of a single item but the visitor can choose the amount. I don't need anything as complex as a shopping cart.

Any help appreciated.  
Enter Amount: <asp:TextBox ID="TextBox1"  Font-Bold="true" Columns="3" runat="server" Visible="true">1</asp:TextBox>
    Price: <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("P_ID") %>' />

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Faizan SarwarSoftware / Database DeveloperCommented:
In its simple form
drop another button name Update Cart
and when user click on the update cart button after changing values simply get the new values do the calculation and display the new results
Please see the code below, i am not taking any value from the database but hardcoding it with any value, hope you get an idea from this.
 <asp:TextBox ID="txtOne" runat="server" Text="1" AutoPostBack="True" 
       <asp:TextBox ID="txtTwo" runat="server" Text="2"></asp:TextBox>
 protected void txtOne_TextChanged(object sender, EventArgs e)
        int i = 0;
        int j = 0;
        i = Convert.ToInt32(txtOne.Text);
        j = i * 3;
        txtTwo.Text = Convert.ToString(j);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why don't you use javascript to do that?

Create a JS function on your asp.net page

<script type="text/javascript">
        function UpdatePrice(value, txtPrice) {

            var old_price = txtPrice.getAttribute("value");
            txtPrice.setAttribute("value", old_price * value);

On Page_Load add this:

your_txtQuantity.Attributes.Add("onblur", String.Format("UpdatePrice(this.value,{0});", YourTxtPrice.ClientID));

Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Anurag ThakurTechnical ManagerCommented:
javascript approach as suggested by tiagosalgado looks like the best approach. but thr only problrm will be on browsers where javascript is disabled
nedloganAuthor Commented:
Thanks, straightforward and easy to understand.
nedloganAuthor Commented:
Thanks all for your input. I chose the asp.net solution.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.