Search code examples
c#asp.netvisual-studiotextboxrepeater

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></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 ;-)


Solution

  • 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
    }