开发者

ASP.Net C# asp:TextBox Only 'Default Value Passed

<asp:Repeater ID="Cartridges" runat="server" onitemcommand="Cartridges_ItemCommand">
     <ItemTemplate>
          <p class="cartqty">QTY <asp:TextBox ID="cartQty" Text="0" runat="server"></asp:TextBox>&l开发者_C百科t;/p>
          <div class="cartbuy2"><asp:LinkButton ID="buy" runat="server" CommandName="AddtoCart" CommandArgument='<%#Eval("cartID") %>' Text="Buy"></asp:LinkButton></div>
     </ItemTemplate>
</asp:Repeater>

Why does the TextBox cartQty only return the default value of 0 rather than the value entered and submitted? If I change the value to 3 it submits 3 regardless of what's typed.

Here's the codebehind for cartQty

LinkButton lb = (LinkButton)e.CommandSource;
int varCartQty = Convert.ToInt32(((TextBox)lb.Parent.FindControl("cartQty")).Text); 

Thank you ;-)


I can only guess:

You are binding the Repeater to it's DataSource on every postback but not only if(!Page.IsPostBack)


I doubt your repeater is rebinded. When you click the button your page_load event is called before your click handler, where your repeater is binded.

So you need to take care of that.

if(!IsPostBack)
{
   //Put repeater binding code here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜