Панель обновления обновляет всю страницу - Ajax не работает - PullRequest
0 голосов
/ 01 мая 2018

Я использую концепции главной страницы для своего приложения. У меня есть следующий код на странице aspx

У меня есть gridview и текстовое поле внутри, и я связываю это gridview из codebehind (основываясь на значении db, у меня будет много строк на стороне клиента). Всякий раз, когда я ввожу значение в текстовое поле, загружается вся страница, и ajax не работает. В чем ошибка в этом коде. Я уже добавил скрипт-менеджер на главной странице. Он всегда загружает всю страницу. Поскольку это понятия главной страницы, следующий код находится внутри 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 голосов
/ 01 мая 2018

Я надеюсь, что решением будет удаление UpdateMode, тогда первое решение, которое пришло мне в голову:

1 - Измените UpdateMode на Conditional и установите ChildrenAsTriggers на false, чтобы у вас было что-то вроде:

<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>
   ........
   ......

2- Второй: если первый не работает, удалите UpdateMode панели обновления и определите триггер для этого текстового поля, чтобы код был что-то вроде

<asp:UpdatePanel ID="updPnl" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="txtQuantity" AutoPostBack="true" OnTextChanged="txtQuantity_TextChanged" ....
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="txtQuantity" EventName="TextChanged" />
                </Triggers>
            </asp:UpdatePanel>
            .......

Надеюсь, это поможет вам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...