Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Findcontrol with a text box problem

Status
Not open for further replies.

vincentw56

IS-IT--Management
Oct 10, 2002
47
0
0
US
I have created a product listing page that has a textbox next to the add to cart button. The textbox is to allow the customer to put in a quantity. The problem is the default value is over-ridding the user entered value. I have included some of the code below. Anyone seen this before? Thanks.

ASPX Code:
Code:
<form id=&quot;frmproduct&quot; runat=&quot;server&quot;>
  <asp:repeater id=&quot;rpProducts&quot; runat=&quot;server&quot; onitemcommand=&quot;rpProducts_ItemCommand&quot;>
<itemtemplate>
    <div style=&quot;FLOAT: left; WIDTH: 245px&quot; class=&quot;prodprice&quot;>QTY:
    <asp:textbox id=&quot;txtQTY&quot; runat=&quot;server&quot; width=&quot;40px&quot; text=&quot;1&quot; />
    <asp:linkbutton runat=&quot;server&quot; commandname=&quot;AddToCart&quot; id=&quot;lbAddToCart&quot;>
    <img alt=&quot;Add To Cart&quot; src=&quot;images/addtocart.gif&quot; border=&quot;0&quot; height=&quot;22&quot; width=&quot;100&quot;></asp:linkbutton></div>
</div>
</itemtemplate>
</asp:repeater></form>

Code Behind:
Code:
Sub rpProducts_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)

Dim strTitle As Label = rpProducts.Items(e.Item.ItemIndex).FindControl(&quot;lblTitle&quot;)
        Dim strPrice As Label = rpProducts.Items(e.Item.ItemIndex).FindControl(&quot;lblPrice&quot;)
        Dim strPartNo As Label = rpProducts.Items(e.Item.ItemIndex).FindControl(&quot;lblPartNo&quot;)
        Dim strQTY As TextBox = rpProducts.Items(e.Item.ItemIndex).FindControl(&quot;txtQTY&quot;)

Response.Write(txtQTY.Text)

End Sub
 
Are you remembering to wrap the Repeater binding code in the Page_load event in a
Code:
if not page.ispostback then...
block? If you don't do this then the Repeater will be rebound every time the page is loaded (which includes postback) and you will loose any entered values.

James :)

James Culshaw
james@miniaturereview.co.uk
 
No I don't think I am. I am not sure what you mean by binding code? Do you have an example or maybe a little more information? I am still fairly new at this. Thanks.
 
Okay I figured out what you meant by that. I got it working. Thanks for your help it works perfectly now.

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top