views:

14

answers:

1

Hello,

The code below works fines when I "hardcode" values but when I add the runat="server" with a binding in the code behind (for the sourceList), I can't anymore add/remove element from a list to another via jQuery

Any idea ?

<div id="Global">
    <select size="10" runat="server" style="width:150px;" class="testMe" id="sourceSelect">
     </select>

    <button type="button" id="btToTarget">></button>
    <button type="button" id="btToSource"><</button>

    <select size="10" runat="server" style="width:150px;" id="targetSelect" >
    </select>    
</div>

$('#btToTarget').click(function() {
    $('#sourceSelect option:selected').appendTo('#targetSelect');
    return false;
});

$('#btToSource').click(function() {
    $('#targetSelect option:selected').appendTo('#sourceSelect');
    return false;
});  
+1  A: 

That's because the ID gets changed once you add runat="server". It will look something like MainContent_Panel1_sourceSelect...

Instead use a class

<div id="Global">
    <select size="10" runat="server" style="width:150px;" class="sourceSelect" id="sourceSelect">
     </select>

    <button type="button" id="btToTarget">></button>
    <button type="button" id="btToSource"><</button>

    <select size="10" runat="server" style="width:150px;" class="targetSelect" id="targetSelect">
    </select>    
</div>

$('#btToTarget').click(function() {
    $('.sourceSelect option:selected').appendTo('#targetSelect');
    return false;
});

$('#btToSource').click(function() {
    $('.targetSelect option:selected').appendTo('#sourceSelect');
    return false;
});  

Check out the Source of the page to see what I mean..

Marko
Yes of course ! you are completely right, thanks,
Kris-I
One more question, I add/remove element in listbox via jQuery but via the codebehind the content are the same then just after binding.
Kris-I