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

2 Answers 2

2

I can only guess:

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

Sign up to request clarification or add additional context in comments.

Comments

1

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
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.