更新面板重新加载整个页面 - Ajax无法正常工作

时间:2018-05-01 06:29:23

标签: asp.net updatepanel

我为我的应用程序使用母版页概念。我在aspx页面中有以下代码

我有一个gridview和一个文本框,我从codebehind绑定这个gridview(基于db值,我将在客户端有很多行)。每当我在文本框中输入一个值时,整个页面都会加载,并且ajax不起作用。这段代码中的错误是什么?我已经在母版页中添加了scriptmanager。它总是加载整个页面。由于它是母版页概念,下面的代码在contentplaceholder

                     的             的                                                

                <tbody>


                    <asp:UpdatePanel ID="updPnl" UpdateMode="Always" runat="server">

                        <ContentTemplate>


                            <asp:GridView ID="grdBOQ" Width="100%" ShowFooter="true" OnRowDataBound="gvBOQDetails_OnRowDataBound" OnRowCommand="grdBOQ_RowCommand" ShowHeaderWhenEmpty="true" AutoGenerateColumns="false" runat="server" CssClass="gvBOQdatatable">

                                <Columns>

                                    <asp:TemplateField HeaderText="Sl No:">
                                        <ItemTemplate>
                                            <%#(grdBOQ.PageSize * grdBOQ.PageIndex) + grdBOQ.Rows.Count + 1%>
                                        </ItemTemplate>


                                        <HeaderStyle HorizontalAlign="Center" Width="40px" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" />
                                        <FooterTemplate>
                                            <div style="text-align: center;">
                                                <%#(grdBOQ.PageSize * grdBOQ.PageIndex) + grdBOQ.Rows.Count + 1%>
                                            </div>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Item ID"  >
                                        <HeaderStyle CssClass="HiddenCol" />
                                        <ItemTemplate>
                                            <asp:Label ID="lblItem_ID" runat="server" Text='<%# Bind("BOQ_ITEM_ID") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Right" CssClass="HiddenCol" />
                                        <FooterTemplate>
                                            <div style="text-align: center;">
                                                <asp:Label runat="server" Text='' ID="lblItemID"></asp:Label>
                                            </div>
                                        </FooterTemplate>
                                        <FooterStyle CssClass="HiddenCol" />

                                    </asp:TemplateField>


                                    <asp:TemplateField HeaderText="Section">
                                        <ItemTemplate>
                                            <asp:Label runat="server" Text='<%# Bind("BOQ_SECTION") %>' ID="lblSection"></asp:Label>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="ddlBOQSection" OnSelectedIndexChanged="ddlSectionItem_SelectedIndexChanged"
                                                onmouseover="this.size=5;" onmouseout="this.size=1;"
                                                Style="max-height: 100px; overflow: auto;" AutoPostBack="true" runat="server">
                                            </asp:DropDownList>


                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Category Name">
                                        <ItemTemplate>
                                            <asp:Label runat="server" Text='<%# Bind("Category_Name") %>' ID="lblCategoryName"></asp:Label>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <asp:Label runat="server" Text='' ID="lblCatName"></asp:Label>

                                        </FooterTemplate>
                                    </asp:TemplateField>


                                    <asp:TemplateField HeaderText="Category Description">
                                        <ItemTemplate>
                                            <asp:Label runat="server" Text='<%# Bind("Description") %>' ID="lblCategoryDescription"></asp:Label>
                                        </ItemTemplate>

                                        <FooterTemplate>
                                            <asp:Label runat="server" Text='' ID="lblCatDesc"></asp:Label>

                                        </FooterTemplate>

                                    </asp:TemplateField>


                                    <asp:TemplateField HeaderText="Quantity">
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtQuantity" AutoPostBack="true" OnTextChanged="txtQuantity_TextChanged" class="form-control" runat="server" Text='<%# Bind("QUANTITY") %>' Style="width: 80px" MaxLength="8"></asp:TextBox>
                                        </ItemTemplate>


                                        <FooterTemplate>
                                            <div style="text-align: center">
                                                <asp:TextBox ID="txtQuantityDyn" class="txtlbl" AutoPostBack="true" OnTextChanged="txtQuantityDyn_TextChanged" ReadOnly="true" Style="width: 80px" Text='0' runat="server" />
                                            </div>
                                        </FooterTemplate>

                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Unit">
                                        <ItemTemplate>
                                            <asp:Label runat="server" Text='<%# Bind("UOM_Name") %>' ID="lblUnit"></asp:Label>
                                        </ItemTemplate>


                                        <FooterTemplate>
                                            <asp:Label runat="server" Text='' ID="lblSectionUnit"></asp:Label>

                                        </FooterTemplate>

                                    </asp:TemplateField>


                                    <asp:TemplateField HeaderText="Unit Rate">
                                        <ItemTemplate>

                                            <asp:TextBox ID="lblUnitRate" class="txtlbl" ReadOnly="true" runat="server" Text='<%# Bind("SellingPrice_Per_UOM")  %>'></asp:TextBox>
                                        </ItemTemplate>

                                        <FooterTemplate>
                                            <asp:TextBox ID="TextBoxSectionUR" class="txtlbl" ReadOnly="true" Text="0.00" runat="server" />
                                        </FooterTemplate>

                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Total">
                                        <ItemTemplate>

                                            <asp:TextBox ID="lblTotalPrice" class="txtlbl" ReadOnly="true" runat="server" Text='<%# Bind("TOTAL") %>'></asp:TextBox>



                                        </ItemTemplate>

                                        <FooterTemplate>
                                            <asp:TextBox ID="TextBoxURT" class="txtlbl" ReadOnly="true" Text='0.00' runat="server" />
                                        </FooterTemplate>


                                    </asp:TemplateField>



                                    <asp:TemplateField HeaderText="Action">


                                        <FooterStyle HorizontalAlign="Right" />
                                        <FooterTemplate>
                                            <asp:Button ID="ButtonAdd" runat="server" Text="Add New BOQ" CommandArgument="<%# Container.DataItemIndex %>" CommandName="addNew" />
                                        </FooterTemplate>

                                    </asp:TemplateField>



                                </Columns>

                            </asp:GridView>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </tbody>
            </table>
        </div>

文本框更改了代码

protected void txtQuantity_TextChanged(object sender, EventArgs e)
        {
            if (Session[clsCommon.SESSION_USER_ROLE_ID].ToString() == clsCommon.gConst_UserRole_PM.ToString())
            {

                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "OptionHide()", true);
            }
            if (Session["RowCount"]==null)
            { 
            Session["RowCount"] = grdBOQ.Rows.Count;
            }
            else
            { 

            int rowCount = grdBOQ.Rows.Count;
            }
            TextBox thisTextBox = (TextBox)sender;
            GridViewRow currentRow = (GridViewRow)thisTextBox.Parent.Parent;
            int rowindex = 0;
            rowindex = currentRow.RowIndex;
            Label txt = (Label)currentRow.FindControl("lblItem_ID");
            int val = Convert.ToInt32(txt.Text);

            DataSet dsBOMInvoice = new DataSet();
            objInvoiceUser.P_BOQ_ID = val;

            dsBOMInvoice = objInvoiceUser.GetBOMValues();



            decimal bomQuantity = 0;
            decimal bomPrice;



            if (btnobcInvoice.Visible == true)
            {
                clsContractorInvoiceEdit objConInvEdit = new clsContractorInvoiceEdit();

                objInvoiceUser.P_BOQ_ID = val;
                objInvoiceUser.P_ASSIGN_INVOICE_ORDER_ID = intAssignOrderID;
                DataSet dsBOMNew = objInvoiceUser.GetAllPMBOM();
                var list = new List<KeyValuePair<string, int>>();
                string bom_section;
                int bom_new_count = dsBOMNew.Tables[0].Rows.Count;
                decimal result = 0.000M;
                Session["result"] = "0.00";
                if(bom_new_count>=1)
                {

                    bom_section = dsBOMNew.Tables[0].Rows[0]["BOM_SECTION"].ToString().ToLower();
                    decimal value = Convert.ToDecimal(thisTextBox.Text);

                    objConInvEdit.P_BOQ = val;
                    objConInvEdit.P_BOM = bom_section;
                    objConInvEdit.P_Quantity = value;
                    objConInvEdit.P_order_ID = intAssignOrderID;
                    objConInvEdit.P_type = 1;
                    objConInvEdit.P_mode = 1;
                     result = objConInvEdit.InsertUPdateConINVEdit();

                     Session["result"] = result;

                }

                //    Response.Write("<script>alert('Hello');</script>");


            }

            else
            {

                Session["result"] = thisTextBox.Text;

            }


            if (dsBOMInvoice.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dsBOMInvoice.Tables[0].Rows)
                {


                    var BOQ_ID = dr["BOM_ID"].ToString();


                    foreach (GridViewRow BOMrow in grdBOM.Rows)
                    {


                        Label lblBOMItem_ID = (Label)BOMrow.FindControl("lblBOMItem_ID");
                        if (lblBOMItem_ID.Text == BOQ_ID)
                        {

                            TextBox txtBOMQuantity = (TextBox)BOMrow.FindControl("txtBOMQuantity");
                            txtBOMQuantity.Text = Session["result"].ToString();


                        }


                    }


                }

            }
            decimal ld_tot_tots = 0, TotalbomPrice = 0;
            foreach (GridViewRow BOMrows in grdBOM.Rows)
            {
                decimal ld_tots = 0;

                string BOmQuantity = ((TextBox)BOMrows.FindControl("txtBOMQuantity")).Text;   //tiru   
                if (BOmQuantity != string.Empty && BOmQuantity != null && BOmQuantity != "")
                {

                    bomQuantity = decimal.Parse(((TextBox)BOMrows.FindControl("txtBOMQuantity")).Text);
                }

                //bomQuantity = decimal.Parse(((TextBox)BOMrows.FindControl("txtBOMQuantity")).Text);
                bomPrice = decimal.Parse(((TextBox)BOMrows.FindControl("lblBOMUnitRate")).Text);

                TotalbomPrice = (bomQuantity * bomPrice);
                TextBox totalBOM = (TextBox)BOMrows.FindControl("lblBOMTotalPrice");
                totalBOM.Text = TotalbomPrice.ToString();


                ld_tots = Convert.ToDecimal(((TextBox)BOMrows.FindControl("lblBOMTotalPrice")).Text);
                ld_tot_tots = ld_tot_tots + ld_tots;

            }
            // grandBOMTotal = Convert.ToDecimal(ld_tot_tots) + Convert.ToDecimal(TotalbomPrice);
            lblBOMtotal.Text = Convert.ToDecimal(ld_tot_tots).ToString();

            lblGrandtotal.Text = Decimal.Add(Convert.ToDecimal(lblBOMtotal.Text), Convert.ToDecimal(lblBOQTotal.Text)).ToString();



            lblFinalGrandTotal.Text = Decimal.Add(Convert.ToDecimal(lblGrandtotal.Text), Convert.ToDecimal(lblAllGrandtotal.Text)).ToString();


            //BOQ - first Grid

            decimal addQuantity = 0; decimal Quantity = 0; //tiru
            decimal price, TotalPrice, addprice = 0;

            foreach (GridViewRow gvRow in grdBOQ.Rows)
            {
                string quantity_val = ((TextBox)gvRow.FindControl("txtQuantity")).Text;  //tiru
                if (quantity_val != string.Empty && quantity_val != null && quantity_val != "")
                {

                    Quantity = decimal.Parse(((TextBox)gvRow.FindControl("txtQuantity")).Text);
                }
                //decimal Quantity = decimal.Parse(((TextBox)gvRow.FindControl("txtQuantity")).Text);   

                price = decimal.Parse(((TextBox)gvRow.FindControl("lblUnitRate")).Text);

                addQuantity = Convert.ToInt32(((TextBox)grdBOQ.FooterRow.FindControl("txtQuantityDyn")).Text);
                addprice = decimal.Parse(((TextBox)grdBOQ.FooterRow.FindControl("TextBoxSectionUR")).Text);

                TextBox total = (TextBox)gvRow.FindControl("lblTotalPrice");

                TotalPrice = (Quantity * price);

                total.Text = TotalPrice.ToString();



                grandBOQTotal = Decimal.Add(Convert.ToDecimal(grandBOQTotal), Convert.ToDecimal(TotalPrice));


            }


            TotalPrice = (addQuantity * addprice);
            grandBOQTotal = Decimal.Add(grandBOQTotal, TotalPrice);

            lblBOQTotal.Text = Convert.ToDecimal(grandBOQTotal).ToString();
            grandBOQTotal = 0;
            lblGrandtotal.Text = Decimal.Add(Convert.ToDecimal(lblBOMtotal.Text), Convert.ToDecimal(lblBOQTotal.Text)).ToString();

            lblFinalGrandTotal.Text = Decimal.Add(Convert.ToDecimal(lblGrandtotal.Text), Convert.ToDecimal(lblAllGrandtotal.Text)).ToString();


        }

1 个答案:

答案 0 :(得分:0)

我希望解决方案是删除sudo mkdir -p /usr/local/Frameworks sudo chown -R $(whoami) /usr/local/* brew link python@2 然后我想到的第一个解决方案是:

1-将UpdateMode更改为UpdateMode,然后将Conditional设置为ChildrenAsTriggers,这样您就可以拥有以下内容:

false

2-第二个:如果第一个不起作用,则删除更新面板的<asp:UpdatePanel ID="updPnl" UpdateMode="Conditional" ChildrenAsTriggers="false" runat="server"> <ContentTemplate> ...... <asp:TextBox ID="txtQuantity" AutoPostBack="true" OnTextChanged="txtQuantity_TextChanged" class="form-control" runat="server" Text='<%# Bind("QUANTITY") %>' Style="width: 80px" MaxLength="8"></asp:TextBox> ........ ...... 并为该文本框定义一个触发器,使代码类似

UpdateMode

希望这些能帮到你。

相关问题