Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:58:20+00:00 2026-06-12T23:58:20+00:00

I have a bool method which calculates the sum (quantity*price) it works fine. When

  • 0

I have a bool method which calculates the sum (quantity*price) it works fine.
When I call the method from one button it works fine.

protected void btnupdate_Click(object sender, EventArgs e)     
    {
        calculate_sum();
    }

I also need to call it again from different button.
So I try to write this:

if(calculate_sum())
        {
            something
        }
        else
        {
            something
        }

The problem is with the second button it doesn’t perform the method it just takes the value which was calculated before when button btnupdate was clicked and doesn’t comes in to perform it again.

The aspx page is wrapped in updatepanels with triggers maybe there’s something to do with that?

Here is the code of the method:

public bool calculate_sum()
    {

        bool is_ok = true; ;
        double totalsum = 0;
        int qty = 0; ;
        string p = "";
        for (int i = 0; i < GridView2.Rows.Count; i++)
        {
            if (GridView2.Rows[i].RowType == DataControlRowType.DataRow)
            {
                TextBox txtqty = GridView2.Rows[i].FindControl("lblquantity") as TextBox;

                 p = GridView2.Rows[i].Cells[0].Text.ToString();

                 if (Int32.TryParse(txtqty.Text, out qty))
                 {
                     if (qty > 0)
                     {
                         double pr = Convert.ToDouble(p.ToString());
                         //total per row
                         double tcost = qty * pr;
                         totalsum = totalsum + tcost;
                         GridView2.Rows[i].Cells[6].Text = Convert.ToString((tcost));

                     }
                     else
                     {
                         lblGrandTotal.Visible = true;
                         lblGrandTotal.Text = "enter only numbers greater than 0";
                         lblGrandTotal.ForeColor = System.Drawing.Color.Red;
                         is_ok = false;

                     }
                 }

                     else
                     {
                         lblGrandTotal.Visible = true;
                         lblGrandTotal.Text = "enter only numbers greater than 0";
                         lblGrandTotal.ForeColor = System.Drawing.Color.Red;
                         is_ok = false;
                     }
                 }



        }
        if (is_ok)
        {
            lblGrandTotal.ForeColor = System.Drawing.Color.Black;
            lblGrandTotal.Text = Convert.ToString((totalsum));
            return is_ok;

        }
        else
        {
            return is_ok;
        }

    }

Here the aspx page:

<%@ Page Title="Check out" Language="C#" MasterPageFile="~/MasterPage/MasterPage.master" AutoEventWireup="true" CodeFile="CheckOut.aspx.cs" Inherits="CheckOut" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    </asp:ScriptManagerProxy>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" 
        UpdateMode="Conditional">

    <ContentTemplate>



    <asp:HiddenField ID="hfGrandTotal" runat="server"  />
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" >

        <Columns>
        <asp:BoundField DataField="Price" HeaderText="Price" ItemStyle-CssClass="price" >

<ItemStyle CssClass="price"></ItemStyle>
            </asp:BoundField>

                         <asp:TemplateField HeaderText="ProductID" Visible="False">
                <ItemTemplate>
                    <asp:Label ID="lblID" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderText="ProductName">
                <ItemTemplate>
                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

             <asp:TemplateField HeaderText="Summary">
                <ItemTemplate>
                    <asp:Label ID="lblSum" runat="server" Text='<%# Eval("Summary") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderText="picPath" Visible="False">
                <ItemTemplate>
                    <asp:Label ID="lblPic" runat="server" Text='<%# Eval("picPath") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText = "quantity">
            <ItemTemplate>
                <asp:TextBox ID="lblquantity" runat="server"  >1</asp:TextBox>

            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText = "Total">
            <ItemTemplate>
                <asp:Label ID="lblTotal" runat="server" ></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

        </Columns>

    </asp:GridView>
        <br />


total sum:
            <asp:Button ID="btnupdate" runat="server" Text="update quantity" 
                onclick="btnupdate_Click" ValidationGroup="panel1" />
<asp:Label ID="lblGrandTotal" runat="server" ></asp:Label>
</ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnupdate" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    <br />
    <br />
    <br />
    <br />
    <br />

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
    <ContentTemplate>


    <asp:Table ID="Table1" runat="server" CellPadding="7" CellSpacing="7" 
        CaptionAlign="Bottom" HorizontalAlign="Center" BorderStyle="Solid" BorderWidth="1" 
                BorderColor="Black" Height="305px" Width="408px">
        <asp:TableHeaderRow BorderStyle="Solid" BorderWidth="1" BorderColor="Black">
        <asp:TableCell ColumnSpan="3" BorderStyle="Solid" BorderWidth="1" BorderColor="Black">customer details</asp:TableCell>
        </asp:TableHeaderRow>

        <asp:TableRow runat="server" >

            <asp:TableCell runat="server" >  
            <asp:TextBox ID="TextBox1" runat="server" Width="150px"></asp:TextBox>
                &nbsp; &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ForeColor="Red" ErrorMessage="חובה" ControlToValidate="TextBox1" Text="requierd" ValidationGroup="panel2"></asp:RequiredFieldValidator>
            </asp:TableCell>

            <asp:TableCell runat="server">    
            <asp:Label ID="Label1" runat="server" Text="name"></asp:Label>
           </asp:TableCell>

        </asp:TableRow>
       <asp:TableRow ID="TableRow1" runat="server">

            <asp:TableCell ID="TableCell1" runat="server">  
            <asp:TextBox ID="TextBox4" runat="server" Width="150px" CausesValidation="True"></asp:TextBox>
            &nbsp; &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ForeColor="Red" ErrorMessage="חובה" ControlToValidate="TextBox4" Text="requierd" ValidationGroup="panel2"></asp:RequiredFieldValidator>
               <br /> <asp:RegularExpressionValidator ID="RegularExpressionValidator1"  runat="server" ErrorMessage="הקלד מספר טלפון" ControlToValidate="TextBox4" ForeColor="Red" ValidationExpression="^(02|03|04|08|09|050|052|054|057|074|077)\-\d{7,8}$"></asp:RegularExpressionValidator>
            </asp:TableCell>

            <asp:TableCell ID="TableCell2" runat="server">    
            <asp:Label ID="Label4" runat="server" Text="phone"></asp:Label>

           </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow runat="server">

            <asp:TableCell runat="server">   

            <asp:TextBox ID="TextBox2" runat="server" Width="150px" CausesValidation="True"></asp:TextBox>
           &nbsp; &nbsp; <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ForeColor="Red"  ErrorMessage="חובה" ControlToValidate="TextBox2" Text="requierd" ValidationGroup="panel2"></asp:RequiredFieldValidator>
            </asp:TableCell>

       <asp:TableCell>
    <asp:Label ID="Label2" runat="server" Text="address"></asp:Label>
    </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow runat="server">

            <asp:TableCell runat="server">
           <asp:TextBox ID="TextBox3" runat="server" Width="150px"></asp:TextBox>
           &nbsp; &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ForeColor="Red" ErrorMessage="חובה" ControlToValidate="TextBox3" Text="requierd" ValidationGroup="panel2"></asp:RequiredFieldValidator>
           <br />
                <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="only digits" ControlToValidate="TextBox3" ForeColor="Red" MinimumValue="1000" MaximumValue="9999999999999999" ValidationGroup="panel2"></asp:RangeValidator>
            </asp:TableCell>

            <asp:TableCell runat="server">

             <asp:Label ID="Label3" runat="server" Text="number"></asp:Label>
            </asp:TableCell>
        </asp:TableRow>

        <asp:TableRow>
        <asp:TableCell ColumnSpan="3">
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="pay" Width="150" ValidationGroup="panel2" />
        </asp:TableCell>
        </asp:TableRow>

        <asp:TableRow>
        <asp:TableCell ColumnSpan="3">
         <asp:Label ID="lblmessage" runat="server" Text="Label"  
        Font-Size="XX-Large" Visible="False"></asp:Label>

        </asp:TableCell>
        </asp:TableRow>
    </asp:Table>



    <asp:Button ID="btnPrint" runat="server"  Text="print" 
        onclick="btnPrint_Click" Visible="False" />

    </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnPrint" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    </asp:Content>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:58:21+00:00Added an answer on June 12, 2026 at 11:58 pm

    Your question still isn’t very clear…

    Is the “second button” you’re referring to named “Button1” ?

    If so – notice that it is in a different UpdatePanel then the Grid and the “Update” button.
    When the second UpdatePanel is triggered (from Button1), changes that were made in the grid (which is in the other UpdatePanel) are not necessarily passed along with it back to the server.

    I would recommend:

    1. Temporarily remove both UpdatePanels and see if it works as you want. If it does, you know the culprit and changing the UpdatePanel’s UpdateMode to Always might solve your problem.

    2. If this does NOT solve your problem, do as @JonSkeet suggested in the comments and create a short demo that shows the problem so we can better help you out…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that overrides the TextBox ProcessCmdKey method: protected override bool ProcessCmdKey(ref Message
I have a method which have this signature public static IList<T> GetBy<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression)
I have a UIButton which calls a method from another UIViewController , that method
I have a method which returns a bool value, with several exit points. However,
I have the username entered from a form Which method to use if that
I have the following method which is used to populate a DAO from the
I have a method GetSelectedServices() which returns Selected Nodes from a Tree List, Expecting
I have a method which returns a bool value. I want to execute that
I have a method which basically looks at a variable and if its bool
I have a method which is given the parameter bool sortAscending. Now I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.