proseidon
proseidon

Reputation: 2305

JQuery Vs. C#: Using a master textbox

I have a list of 100+ textboxes on my page. I want to have one textbox at the top that can change all of them to its value, yet still have the others able to be independent (as in, using one variable for all wouldn't work). They should be able to be changed individually, with the master one sort of acting as a "Change All".

My question is, would this work better by looping through and doing a postback in c#? Or can I dynamically change them all in jquery? Which would you recommend?

Upvotes: 1

Views: 116

Answers (2)

Sushanth --
Sushanth --

Reputation: 55750

Using jQuery would be the best option.. As there is too much of load using the server side controls..

Check this FIDDLE

<input type="text" class="master"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>
<input type="text" class="child"/>​

$(document).ready(function() {
    $('.master').on('change', function() {

       $('.child').val(  $(this).val() );
    });
});​

Upvotes: 2

Josh Mein
Josh Mein

Reputation: 28645

I would highly recommend changing them all with jquery. It could be as simple as something like this:

$('#txt_Master').change(function() {
    $('.childTextBoxes').val($(this).val());
});

Upvotes: 8

Related Questions