我有一个表单,从那里导航到我的表单,那里有一个数量文本框。之前我输入的是数量。现在,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>
提前致谢。
最佳答案
OnTextChanged
仅当您在文本框中进行更改并跳出该字段时才会发生。或者您可以在文本框上说 AutoPostBack
,当文本框失去焦点时将触发回发。
当您在文本框中键入内容时,OnTextChanged
事件不会被触发。 OnTextChanged
是服务器端事件,仅在回发页面时触发。在页面上的文本框中键入内容不会将页面发回,因此此事件只会在页面以不同方式发布后触发,例如:单击按钮等。因此,您要确保在更改文本后,您要搬出文本框。
使用更新面板很好,一旦发生回发,TextChanged 事件也会在页面生命周期的适当阶段被调用。
此外,尝试保留文本框代码相同但删除 UpdatePanel。换句话说,完全排除 AJAX 并查看您的事件是否在常规回发期间触发(以及您是否在预期时获得回发)。这肯定有助于缩小问题范围。
如果您希望在每次按下按键时触发此事件(在您输入时),这将有所帮助:How to make an ASP.NET TextBox fire it's onTextChanged event fire in an AJAX UpdatePanel?
关于c# - asp.net中自动调用文本框textchanged事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18681317/