I have an ASP usercontrol name ListItem. Each ListItem has 2 ASP controls on it : a label lblIndex and a button btnAction
On my page, I load 10 ListItem into a panel and set lblIndex on each ListPanel an appropriate index.
ListItem 1 : lblIndex.value = '#1'
ListItem 2 : lblIndex.value = '#2'
...
ListItem 10 : lblIndex.value = '#10'
How do I write Javascript that, each time when I click the button on a ListItem, the appropriate lblIndex‘s value will appear(through an Alert()). I.e. when I click the btnAction on the 2nd ListItem, the text ‘#2’ will come out.
Thank you
to facilitate your life, use jQuery when writing javascript.
in that in mind, let’s assume that your
ListItemcontrol outputs aullist with anid… make sure that you had a class, let’s imagine that you namedlist-itemso at the end you will have:Now, you say you some sort of a button inside that list…
Once again, explicit give that button a class name, for example:
inside-buttonI don’t know how you have all texts, but I’ll again assume that will be a
hiidenfield with the text to alert …some thing like:
and assuming you have 10 lists with several buttons you can simple write:
that 1st line says: “Foreach DOM element that has a class name of
inside-buttonattach the click event”and inside you fire what you want to do
From your question, you only want to perform something on that list:
then you can
alert()it.All together: