JQuery Auto generated Control ID Selector in ASP.NET

Hello guy's today I am going to share information about Jquery Page Controls selector.

In common ways we are having lots of different type of selectors like "document.getElementById('ElementID')"  etc.

and in Jquery we are having $("#id_of_Element") but in case of normal HTML controls it will work but when we are working with MASTER PAGE scenario in ASP.NET and control having runat ="server" Tag at this time this selectors will not work as the contolrs ID's are getting change by the View Engine of ASP.NET and it is becoming like: ctl00_ContentPlaceHolderID_ControlID so it is harder to select ID by normal $("#ID") selector.

Below is the solution :

In this solution I had to auto generate 6 Checkbox by C# (In next post I'll show you how to auto generate Checkbox or Dynamically generate Checkbox on webpage ) and we need mark all as Checked and Unchecked.

$(document).ready(function () {

var chkAll = $("[id$=_cbStatus_6]");

            chkAll.click(function () {

                $("[id$=_cbAllHdn]").attr("Value", chkAll.prop("checked").toString());

for (var i = 0; i < 6; i++) {

                    $("[id$=_cbStatus_"+i+"]").attr("Checked", chkAll.prop("checked"));

                }

                  });

        });

You can modify the above code as required in you project main part is $("[id$=_ControlID]"); .

I hope it has helped you.

Regards,

Anand

Comments

Post a Comment

Thanking you for the comment.

Technology