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 8456635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:35:45+00:00 2026-06-10T12:35:45+00:00

In in aspx page, there is a grid view, that has template control for

  • 0

In in aspx page, there is a grid view, that has template control for checkbox, something like this

<asp:gridview .....
  <columns>
    <asp:TemplateField>
      <HeaderTemplate>
        <asp:CheckBox ID="chkAll" runat="server"/>
      </HeaderTemplate>
      <ItemTemplate>
        <asp:CheckBox ID="chkSelect" runat="server"/>
      </ItemTemplate>
    </asp:TemplateField>
...

Now if I write something like

$(#'<%=chkSelect.ClientID%>').something( function() {});

I get an error saying ‘chkSelect doesn’t exists in current context, which is pretty obvious, because this element will exist when griddata is loaded, what I have done is bind the change events of the checkbox to a delegate..

$("body").delegate(":checkbox", "change", function () {
                custList = $(':checkbox:checked').map(function () { return $(this).closest('tr').find('.grdCustName').text() }).get();
                $('#<%=hdnFromCustomer.ClientID %>').val(custList);
            }

which is again working as it should, the problem is I need to know if a checkbox with a particular id (for ex here, chkAll) is changed(clicked), then select all checkbox, checking all in not an issue, I can do this with something like $(':checkbox').attr(checked, 'on') or something.

But the problem is, if I write
$('#<%=chkAll.ClientID %>'), it doesn’t allows me to, because this checkbox isn’t present in DOM at time of start, but will be available when user clicks showReport button and grid is populated.

So, basically, my question is how can I select, or what selector should I use to select this checkbox (or any other element) in DOM that doesn’t exist but will exist at some time in future?

EDIT: In response to some answers, the problem is not binding, I HAVE DONE SO by using delegate(), which I also could have done by using .on() or .live(). The problem is as as Felix Kling commented, he hit the nail on the head, (read his comment(s) and my reply to him). The problem is the element doesn’t exists in the DOM at page startup time. It is build dynamically when user clicks the showReport button, and gridview is populated with data, this is where this element is created. Though I approach described by Yoeri may/may not work, I wanna know is there any possible way (by jQuery of course!) that I could select such an element as described in this case, or is my only option to look for like alternative like the one Yoeri answered?

  • 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-06-10T12:35:47+00:00Added an answer on June 10, 2026 at 12:35 pm

    Why not selecting the chkAll box on a custom attribute or class?

    I often use an action attribute to bind event to … just to keep all things consistent and seperated from css classes (which are not for binding behaviour to it but for style 😉

    <input type="check" action="checkAll"
    ...
    $('input[action=checkAll]').delegate(....) 
    

    As for adding an action attribute, you can look here … (to avoid adding an extra span element)
    adding-custom-attributes-to-an-aspcheckbox-control

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://www.dofactory.com/Patterns/PatternFlyweight.aspx There is a UML diagram on that page. It has three different kinds
I have a aspx page that has a GridView with a datasource of an
This is what my aspx page looks like: <asp:TemplateField HeaderText=Detail HeaderStyle-ForeColor=DimGray > <ItemTemplate> <asp:Label
I have asp.net's .aspx page. that have GridView let say GridViewParent and Each row
I have a gridview in an aspx page with c# code behind. Is there
In a .net aspx-Page, I have a gridview with textboxes for prices. There is
Hello Freinds I am new to this Asp.net MVC Control.. I have a page
Is there a simple way of making the static content of an .aspx page
I have a .aspx page that loads three separate .ascx controls to represent adding,
I have a GridView that has it's columns added dynamically in codebehind. I've added

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.