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.
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.
Are you asking for doing this on client side or server side
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) .
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
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:Re peaterCont rolID:_ctl 0
RepeaterControlTypeName:Re peaterCont rolID:_ctl 1
And so on.
For example you can do something like this in javascript
var strSearchCtlName = "RepeaterControlTypeName:R epeaterCon trolID:_ct l" + _KitGroupRowIndex + ":EmbededUserControlContro l:_ctl" + _KitGroupIndex + ":RepeaterControlTypeName: RepeaterCo ntrolID:Te xtBox:_ctl "+KitGroup RowIndex ;
var allElements = document.forms["FormID"].e lements;
for (var i=0; i<allElements.length; i++)
{
if (allElements[i].name.index Of(strSear chCtlName) != -1)
{
allElements[i].value = // modify the value to new one
}
}
You can just view source of your html page to get the ID's as they are always generated in a same sequencelike
RepeaterControlTypeName:Re
RepeaterControlTypeName:Re
And so on.
For example you can do something like this in javascript
var strSearchCtlName = "RepeaterControlTypeName:R
var allElements = document.forms["FormID"].e
for (var i=0; i<allElements.length; i++)
{
if (allElements[i].name.index
{
allElements[i].value = // modify the value to new one
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Public Sub myLinkButton_Click(sender as object, e as System.EventArgs)
Dim lb as LinkButton = DirectCast(sender, LinkButton)
Dim txtBox as TextBox = DirectCast(lb.NamingContai
txtBox.Text = "Look, I'm in the same row you clicked the linkbutton in!"
End Sub