在下面的代码中我有网格视图,并且有一些控件,其中我有数量文本框,如果我输入一个值,并留下文本框,它应该调用服务器端方法。我尝试所有的控件值得到清除时调用那个方法。帮助我解决这个问题。
<asp:GridView Width="100%" runat="server" ID="gvProduct" AutoGenerateColumns="false" CellPadding="4" ForeColor="#333333" ShowFooter="true"
PageSize-Mode="NumericPages" PageSize="10" PagerStyle-Visible="true" AllowPaging="true" AllowSorting="true"
>
<Columns>
<asp:TemplateField HeaderText="Product Name" ItemStyle-Width="350px">
<ItemTemplate>
<asp:DropDownList ID="ddlProduct" runat="server" OnSelectedIndexChanged="ddlProduct_SelectedIndexChanged" AutoPostBack="true" Style="width: 100%; height:23px" ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Stock" ItemStyle-Width="150px" >
<ItemTemplate>
<center> <asp:TextBox ID="txtCurrentStock" onkeypress="return isNumberKey(event, false);" Height="20px" runat="server" Width="160px" Enabled="false"> </asp:TextBox></center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" ItemStyle-Width="150px">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" onkeypress="return isNumberKey(event, false);" AutoPostBack="true" runat="server" Height="20px" Width="150px" OnTextChanged="txtQuantity_TextChanged" > </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Type" ItemStyle-Width="50px" >
<ItemTemplate>
<center> <asp:Label ID="lblunittype" runat="server" Width="50px" ></asp:Label></center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Required Date" ItemStyle-Width="150px">
<ItemTemplate>
<asp:TextBox ID="txtProductRequiredDate" style="text-align: left" onkeypress="return isNumberKey(event, false);" Height="20px" runat="server" Width="150px" > </asp:TextBox>
<asp:LinkButton ID="lnkDeliveryDate" runat="server" CommandName="DeliveryDate" >select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remove" HeaderStyle-VerticalAlign="Top" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" OnClientClick="return confirmDelete()" >Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" OnClick="btnAdd_Click" class="button" Text="Add New" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle Font-Bold="True" ForeColor="White" />
<FooterStyle HorizontalAlign="Right" />
</asp:GridView>
protected void txtQuantity_TextChanged(object sender, EventArgs e)
{
AddNewRowToGrid()
}
答案 0 :(得分:0)
问题是因为页面生命周期。您需要从生命周期早期的文本框中收集值,而不是触发click事件。我记得在使用Web表单时遇到这样的问题,一旦我切换到MVC,发现生活变得容易多了。