Link to home
Start Free TrialLog in
Avatar of useless_eater
useless_eater

asked on

Gettings values from databound Repeater Item controls and changing them clientside

I have implemented a shopping cart in ASP.Net that is entirely server side.  Items are displayed in repeater controls which are bound to datatables.  On postback I get the datatable from the repeater and keep it in the session object.  It currently posts back to the server whenever the user chooses to add or remove an item from their shopping cart, or if they edit the quantity of an item.  This is working great on a development machine, but can be a bit too slow when deployed on the internet.

My questions is...

If I click on a LinkButton in my Repeater Item to add an item to my basket, how do I modify a text box in the same repeater item so that it stores the quantity. E.g. if I hit "Add", the quantity should be set to 1, and an invisble check box is ticked to indicate that the item has been added.
Avatar of raterus
raterus
Flag of United States of America image

The linkbutton should raise an event on the server, I hope you have that wired correctly so it fires.  When it does...

Public Sub myLinkButton_Click(sender as object, e as System.EventArgs)
  Dim lb as LinkButton = DirectCast(sender, LinkButton)
  Dim txtBox as TextBox = DirectCast(lb.NamingContainer.FindControl("myTextBox"), TextBox)
  txtBox.Text = "Look, I'm in the same row you clicked the linkbutton in!"
End Sub
Are you asking for doing this on client side or server side
Avatar of useless_eater
useless_eater

ASKER

I want to do to this CLIENT SIDE!  I already have it working server side.
hi ,
 you can call a client side javascript function on click of you say "Add" link.

let say function is :  function ChangeValue (element){}
pass this function your link oject.
using that link object id you will know what id prefix is on client side .
In asp.net data bind controls like datagrid , reapeter generates id of controls inside them at run time. this id will have format like some long prefix based on position of control then _ then actual id of your control say your textbox is id given "textboxQuantity".
so this "textboxQuantity" will appear at last of run time generated id.

so having link buttons id you will know  prefix of all controls inside repeater.you need to do some javascript string manipulation to get prefix but you can make it.
then add your textbox id that is  "textboxQuantity". and then you can get that text box control by document.getElementByID(id withprefix) .


 
That's right

You can just view source of your html page to get the ID's as they are always generated in a same sequencelike

RepeaterControlTypeName:RepeaterControlID:_ctl0
RepeaterControlTypeName:RepeaterControlID:_ctl1

And so on.

For example you can do something like this in javascript

var strSearchCtlName      =      "RepeaterControlTypeName:RepeaterControlID:_ctl" + _KitGroupRowIndex + ":EmbededUserControlControl:_ctl" + _KitGroupIndex + ":RepeaterControlTypeName:RepeaterControlID:TextBox:_ctl"+KitGroupRowIndex ;

      var allElements                  =      document.forms["FormID"].elements;
      for (var i=0; i<allElements.length; i++)
      {      
            if (allElements[i].name.indexOf(strSearchCtlName) != -1)
            {
                  allElements[i].value = // modify the value to new one
                  
            }
      }


ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial