[RESOLVED]How to select all ASP.NET controls(especially textboxes) in a form using jQuery

Hi,

I am writing the script code for selecting all ASP.NET textbox controls

$(document).ready(function () {
$('text').addClass('txtCss')
})

the above code is not working,

but it may work for single selection like

$('#txtName').addClass('txtClass')

suppose if there are html input controls then it works fine. Its not working with ASP.NET Controls.

Can anyone tell me the code for selecting all ASP.NET controls

Thanks & Regards

Abhishek Hotte

Hi,

And "text" is? If this is a class you have to use ‘.text’ rather than just ‘text’ (note the dot to tell that you are searching for the text class rather than text tags. See
http://api.jquery.com/category/selectors/ for details (if you want to search for input tags with the type="text" attrribute or whatever…)

Hi,

thanks for replying

No ‘text’ is not a class

For selecting all html controls we are writing the below code

$(document).ready(function () {
$('intput:text').addClass('txtCss')
})

then how to  select  all ASP.NET text boxes controls ?

ASP.NET controls are all rendered ultimately as HTML markup so input:text should work. What is the bad behavior you see? You could select also textarea controls if you have multiple rows textboxes.

Or if you want to distinguish between controls found directly in the ASPX markup and those generated by an asp:TextBox tag then you could add a class name to easily split them apart (and you’ll always be able to apply the class as needed regardless of wether
or not this is a server side control).

(or do you really have "intput" rather than "input" in your actual code??? it would explain that it doesn’t work at all if this is what happens)

Thanks PatriceSc,

Its working..

I add one class name to all TextBox’s 

$(‘.form-control’).addClass(‘txtClass’)

Thank you so much.

Thanks & Regards

Abhishek Hotte

Leave a Reply