Click here to Skip to main content
16,017,922 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I basically want to run the grid jquery UI code when I hit the edit button which is located on my C# side. The examples Iv'e found I haven't been able to use to make my version work.

So I'd appreciate if someone would explain how it's done and how it works since ill need to figure out how to stop the function too by another button click.

the Jquery is the example found here If it helps
http://jqueryui.com/demos/sortable/#display-grid[^]

This code would be on the html side, I need to modify it so that it doesn't run on page load and only runs when Button1 is clicked.
XML
<script>
    $(function() {
        $( "#sortable" ).sortable();
        $( "#sortable" ).disableSelection();
    });
</script>

C#
protected void Button1_Click(object sender, EventArgs e)
{
// this button would be clicked to run the function above activating the sortable grid.
}

EDIT:
Fixed! I needed to add this to the outside
$(document).ready(function() {        
        
    });


EDIT2:

It seems after all of that the problem is that when the page posts back when i hit the button the javascript is turned off like it was never on in the first place a simple onclientClick.... return false; worked in the end.
Posted
Updated 17-Jan-12 22:55pm
v5

1 solution

you have to get the sortable plugin too, here you can download it : http://tablesorter.com/docs/#Download

i usually use the ready method for the sortable plugin

JavaScript
$(document).ready(function() {
  // Handler for .ready() called.
  $( "#sortable" ).tablesorter();
  $( "#sortable" ).disableSelection();
});

so i'm sure that the page has already been loaded

More info : jquery ready

if you really need to activate the function on client click you can use jquery click method
JavaScript
$('input[Id$="Button1"]').click(function () {
  $( "#sortable" ).tablesorter();
  $( "#sortable" ).disableSelection();
})


More info : jquery selectors
More info : jquery click
 
Share this answer
 
v6
Comments
Phoenix234 17-Jan-12 9:02am    
I added this to the page and tried it but nothing happens.

<script type="text/javascript">
$('Id$="Button1"').click(function () {
$("#sortable").sortable();
$("#sortable").disableSelection();
})
</script>

Is there a way to find out if the button or jquery is the part that didn't work?

Did I miss a step for the button version?
nrgjack 17-Jan-12 9:07am    
you have to get the sortable plugin too, here you can download it : http://tablesorter.com/docs/#Download

then you need to add the link in the head like you did for jquery

then you could have a buttom like :

<asp:Button ID="Button1" runat="server" class="buttonToSort" >
$('.buttonToSort').click(function () {
alert("test click");
$("#sortable").sortable();
$("#sortable").disableSelection();
})
Phoenix234 17-Jan-12 9:17am    
my code looks like this but still isn't working, I cant see what I missed? I added the tablesorter, created the button with the same class you used and it doesn't even hit the alert. I just added the full release of that download you sent me including all 4 libraries

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>

<script src="js/Sorter/jquery-latest.js" type="text/javascript"></script>
<script src="js/Sorter/jquery.tablesorter.min.js" type="text/javascript"></script>
<script src="js/Sorter/jquery.tablesorter.js" type="text/javascript"></script>
<script src="js/Sorter/jquery.metadata.js" type="text/javascript"></script>

<script type="text/javascript">
$('.buttonToSort').click(function () {
alert("test click");
$("#sortable").sortable();
$("#sortable").disableSelection();
})
</script>



<asp:Panel ID="sortable" runat="server">


<div>
<asp:Button ID="Button1" runat="server" Text="Edit Mode" class="buttonToSort" onclick="Button1_Click" />
</div>
Phoenix234 17-Jan-12 9:23am    
I just realised we were using the first method, Neither the button.click or the sortable way seem to work
nrgjack 17-Jan-12 9:26am    
you'r using multiple version of the same file
jquery.tablesorter.min.js and jquery.tablesorter.js are the same file ;) the "min" version has no spaces, tab, comments so the js file is the smallest as possible

the same for jquery

try using only
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script src="js/Sorter/jquery.tablesorter.min.js" type="text/javascript"></script>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900