I have a simple function that I want to call in the code behind file name Move and I was trying to see how this can be done and Im not using asp image button because not trying to use asp server side controls since they tend not to work well with ASP.net MVC..the way it is set up now it will look for a javascript function named Move but I want it to call a function named move in code behind of the same view
<img alt='move' id='Move' src='/Content/img/hPrevious.png' onclick='Move()'/> protected void Move(){ }
//based on Search criteria update a new table
protected void Search(object sender EventArgs e) { for (int i = 0; i < data.Count; i++){ HtmlTableRow row = new HtmlTableRow(); HtmlTableCell CheckCell = new HtmlTableCell(); HtmlTableCell firstCell = new HtmlTableCell(); HtmlTableCell SecondCell = new HtmlTableCell(); CheckBox Check = new CheckBox(); Check.ID = data[i].ID; CheckCell.Controls.Add(Check); lbl1.Text = data[i].Date; lbl2.Text = data[i].Name; row.Cells.Add(CheckCell); row.Cells.Add(firstCell); row.Cells.Add(SecondCell); Table.Rows.Add(row); }
}
Scott Guthrie has a very good example on how to do this using routing rules.
This would give you the ability to have the user navigate to a URL in the format /Search/[Query]/[PageNumber] like http://site/Search/Hippopotamus/3 and it would show page 3 of the search results for hippopotamus.
Then in your view just make the next button point to ‘http://site/Search/Hippopotamus/4‘, no javascript required.
Of course if you wanted to use javascript you could do something like this:
But that is much more convoluted than just incrementing the page number parameter in the controller and setting the URL of the next button.