2

我有一个表格,我正在导航到我的表格,在那里我有一个数量的文本框。之前我输入的是数量。现在,IO 有一个工作流程,这就是另一种形式出现的原因。现在,我对文本框文本更改事件进行了大量编码。当我response.redirect形成其他形式时,我也会流动数量并将该数量放入该文本框中。现在我不想写一个新的代码(函数)来做同样的更新过程也将完成。以下是我试图执行并调用文本更改事件的代码。我也在使用更新面板。那么,这就是我的事件没有被解雇的原因吗?任何解决方案,.??

txt_Quantity.TextChanged += new EventHandler(txt_Quantity_TextChanged);



protected void txt_Quantity_TextChanged(object sender, EventArgs e)
    {
    }





 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

            <asp:Panel ID="pnlGrid" runat="server" BorderColor="#339933" Height="400px" BorderStyle="Solid"
                BorderWidth="2px" ScrollBars="Auto" Width="100%">



                <div style="height: 40px; width: 100%; background-color: #339933;">
                    <%-- <img alt="imgrid" src="Images/grid_icon_green.png" style="padding-left: 10px;" />--%>
                    <span style="font-size: 20px; font-family: Calibri; color: White; padding-left: 5px; vertical-align: top">Asset Distribution</span>
                </div>

                <AjaxToolKit:TabContainer ID="TabContainer1" runat="server" Height="400px">
                    <AjaxToolKit:TabPanel ID="tab1" runat="server" TabIndex="0" HeaderText="Basic Information">
                        <ContentTemplate>
                            <table width="100%">

                                <tr>

                                    <td class="r1">Last Code:

                                    </td>
                                    <td>
                                        <asp:Label ID="Lbl_AssetDistriCode" runat="server"></asp:Label>
                                    </td>




                                    <td width="10%" class="r1">Item Code:
                                    </td>
                                    <td width="23%">

                                        <asp:TextBox ID="txt_ItemCode" runat="server" Height="95%" Width="150px" CssClass="txtbxcomp" AutoPostBack="true" OnTextChanged="txt_ItemCode_TextChanged"></asp:TextBox>
                                       <%-- <span style="color: Red;">*</span>--%>
                                        <AjaxToolKit:AutoCompleteExtender ID="AutoCompleteExtender4" runat="server" ServiceMethod="getitem"
                                            ServicePath="WebService.asmx" TargetControlID="txt_ItemCode" CompletionInterval="500"
                                            MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="5">
                                        </AjaxToolKit:AutoCompleteExtender>

                                    </td>

                                    <td width="10%"></td>
                                    <td width="24%"></td>
                                </tr>


                                <tr>

                                    <td class="r1" width="10%">Item Group:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_Item_Grp" runat="server" Height="95%" Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Item_Grp_SelectedIndexChanged">
                                        </asp:DropDownList>
                                       <%-- <span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="10%">Item Type:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_Item_typ" runat="server" Height="95%" Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Item_typ_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="14%">Item Catagory:
                                    </td>
                                    <td width="20%">
                                        <asp:DropDownList ID="ddl_Item_cat" runat="server" Height="95%" Width="150px" CssClass="drpComp"></asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                </tr>


                                <tr>

                                    <td class="r1" width="10%">City:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_city" runat="server" Height="95%"  Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_city_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="10%">Location:
                                    </td>
                                    <td width="24%">
                                        <asp:DropDownList ID="ddl_Loc" runat="server" Height="95%" Width="150px" CssClass="drp" 
                                          >
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <td class="r1" width="10%">Branch:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_Branch" runat="server" Height="95%" Width="150px" CssClass="drpComp" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Branch_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>


                                </tr>




                                 <tr>

                                      <td class="r1" width="10%">Department:
                                    </td>
                                    <td width="24%">
                                        <asp:DropDownList ID="ddl_Dept" runat="server" Height="95%" Width="150px" CssClass="txtbx" AutoPostBack="True"
                                            OnSelectedIndexChanged="ddl_Dept_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>


                                    <td class="r1" width="10%">User:
                                    </td>
                                    <td width="23%">
                                        <asp:DropDownList ID="ddl_User" runat="server" Height="95%" width="150px" CssClass="txtbx"  AutoPostBack="True"></asp:DropDownList>
                                        <%--<span style="color: Red;">*</span>--%>
                                    </td>

                                    <%--<td class="r1" width="15%">Asset Code:
                                    </td>
                                    <td width="19%">
                                        <asp:DropDownList ID="ddl_Asset_code" runat="server" Height="95%" CssClass="txtbx" AutoPostBack="True"></asp:DropDownList>
                                        <span style="color: Red;">*</span>
                                    </td>--%>
                                    <td class="r1" width="10%">Quantity:
                                    </td>
                                    <td width="23%">
                                        <asp:TextBox ID="txt_Quantity" runat="server" Height="95%" Width="150px"  CssClass="txtbxcomp" AutoPostBack="true" OnTextChanged="txt_Quantity_TextChanged"></asp:TextBox>
                                        <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server" TargetControlID="txt_Quantity"
                                            ValidChars="0123456789." Enabled="True">
                                        </cc1:FilteredTextBoxExtender>


                                       <%-- <span style="color: Red;">*</span>--%>

                                    </td>
                                    <td width="10%"></td>
                                    <td width="24%"></td>

                                </tr>



                                <%--<tr>
                                    <td width="15%" class="r1">Mac ID:
                                    </td>
                                    <td width="18%">

                                        <asp:TextBox ID="txt_MacId" runat="server" Height="95%" CssClass="txtbx"></asp:TextBox>
                                        <span style="color: Red;">*</span>
                                    </td>
                                    <td width="15%"></td>
                                    <td width="18%"></td>
                                    <td width="15%"></td>
                                    <td width="19%"></td>
                                </tr>--%>
                            </table>
                        </ContentTemplate>
                    </AjaxToolKit:TabPanel>

</ContentTemplate>

        <Triggers>

            <asp:PostBackTrigger ControlID="btnSave" />
            <asp:PostBackTrigger ControlID="btnUpdate" />
            <asp:PostBackTrigger ControlID="btndelete" />
            <asp:PostBackTrigger ControlID="btnClear" />

        </Triggers>

    </asp:UpdatePanel>

提前致谢。

4

1 回答 1

9

仅当OnTextChanged您在文本框中进行更改并且还从该字段中跳出时才会发生。或者您可以AutoPostBack在文本框中说当焦点从文本框中丢失时将触发回发。

OnTextChanged在文本框中键入时不会触发该事件。OnTextChanged是服务器端事件,仅在页面回发时触发。在页面上的文本框中键入内容不会将页面返回,因此该事件只会在页面以不同的方式发布后触发,例如:按钮单击等。因此,请确保在更改文本后,您将移出的文本框。

使用更新面板很好,一旦回发发生,TextChanged 事件也将在页面生命周期的适当阶段被调用。

此外,尝试保持文本框代码不变,但删除 UpdatePanel。换句话说,完全取消 AJAX 并查看您的事件是否在常规回发期间触发(并且在您期望的时候收到回发)。这肯定有助于缩小问题的范围。

如果您希望触发此事件,则每次生成 KeyStroke(在您输入时)时,这将有所帮助:如何使 ASP.NET TextBox 触发它在 AJAX UpdatePanel 中触发 onTextChanged 事件?

于 2013-09-08T08:35:53.910 回答