Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:58:48+00:00 2026-05-26T16:58:48+00:00

I have an ASP usercontrol name ListItem . Each ListItem has 2 ASP controls

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:58:49+00:00Added an answer on May 26, 2026 at 4:58 pm

    to facilitate your life, use jQuery when writing javascript.

    in that in mind, let’s assume that your ListItem control outputs a ul list with an id… make sure that you had a class, let’s imagine that you named list-item so at the end you will have:

    <div id="ListItem_1" class="list-item">
       ...
    </div> 
    

    Now, you say you some sort of a button inside that list…

    <div id="ListItem_1" class="list-item>
       <input id="ListItem_1_Button_1" type="button" value="I'm a Button" />
    </div> 
    

    Once again, explicit give that button a class name, for example: inside-button

    I don’t know how you have all texts, but I’ll again assume that will be a hiiden field with the text to alert …

    some thing like:

    <div id="ListItem_1" class="list-item>
       <input id="ListItem_1_Button_1" type="button" value="I'm a Button" />
       <input id="ListItem_1_Hidden_1" type="hidden" class="text" value="Text to run" />
    </div> 
    

    and assuming you have 10 lists with several buttons you can simple write:

    $(".inside-button").bind("click", function() {
        // a button was clicked, let's do something
    });
    

    that 1st line says: “Foreach DOM element that has a class name of inside-button attach the click event”

    and inside you fire what you want to do

    From your question, you only want to perform something on that list:

    $(this)  // that will be the .inside-button element, so the Button
       .closest(".list-item")  // get me the closest DOM element with a class name of "list-item"
       .find(".text") // find the DOM elemnt with the class name "text"
       .val();  // let's see what value that element has
    

    then you can alert() it.

    All together:

    $(".inside-button").bind("click", function() {
        // a button was clicked, let's do something
        var txt = $(this).closest(".list-item").find("text").val();
        alert( txt );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET page with 2 user controls registered. The first one has
I have a Todo List (an ASP.MVC UserControl) that for each row has the
How can I dynamically load a usercontrol in ASP.NET if I dont have access
I have a UserControl in my Asp.net project that has a public property. I
I have a usercontrol that hides a div when a button is clicked. <asp:LinkButton
I have an ASP.NET 4.0 home page which displays about 20 product listings. Each
In The Page_Load event of an ASP.NET USercontrol, I have the following Code: If
I have a usercontrol in an asp web forms application that I am working
I have a partial view (UserControl) that implements a simple pager in my Asp.Net
For example, i have this ImageViewer.ascx UserControl: <div class=ImageTumbnails> <asp:ListView ID=ImageList runat=server ItemPlaceholderID=ItemContainer> <LayoutTemplate>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.