[英]How to get value of TextBox in ASP.NET
I have entered a value in the textbox, however when I clicked the button to get the value at server side, it still retrieved the old value. 我已经在文本框中输入了一个值,但是当我单击按钮以在服务器端获取该值时,它仍然会检索旧值。 Here is my code: aspx:
这是我的代码:aspx:
<asp:GridView ID="gvTicketSkus" runat="server" AutoGenerateColumns="false"
CssClass="innergv" HeaderStyle-CssClass="innergvHeader" GridLines="Horizontal"
Width="570px">
<Columns>
<asp:BoundField HeaderText="Sku" DataField="TicketItemCode" />
<asp:BoundField HeaderText="TICKET TYPE" DataField="TicketItemCodeDescription" />
<asp:BoundField HeaderText="Tickets#" DataField="NumberOfWristbandsPerTicket" Visible="false" />
<asp:BoundField HeaderText="PRICE" DataField="Price" DataFormatString="{0:c}" />
<asp:TemplateField HeaderText="QUANTITY">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" TextMode="SingleLine" MaxLength="4" Width="80px" CssClass="quantity" Text="0"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#: C#:
foreach (GridViewRow gvr in gvTicketSkus.Rows)
{
sku = gvr.Cells[0].Text;
quantity = Convert.ToInt32(((TextBox)gvr.FindControl("txtQuantity")).Text);
if (quantity > 0)
{
pendingOrder.Add(sku, quantity);
}
}
As you see when I get the value of txtQuantity, it gave me the old value, instead of the one I type in. 如您所见,当我获得txtQuantity的值时,它给了我旧的值,而不是我输入的值。
I guess there is some issue in postback. 我猜回发中有一些问题。
You can try using 您可以尝试使用
Request.Form[((TextBox)gvr.FindControl("txtQuantity")).ClientID];
To get exactly what was posted to the server. 为了确切地发布到服务器。
You may need to work on the syntax. 您可能需要处理语法。 I can't test it right now.
我现在无法测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.