I have a website that returns search results from Twitter, written in C# ASP.NET. The search works very well.
When the user sees the results I want them to also have a ‘Next Page’ type hyperlink that will perform the search from the last previous result onwards (using Twitter’s next_page data).
How can I preserve properties so that when a link is clicked it will run the search again with different parameters for the next results? I cannot use Form as there is one Form on the page already and MS limits to one Form per page (for runat="server").
Please help, this is driving me nuts.
PS I thought of including code, but not sure which bit to include, as it has more to do with how ASP.NET works as much as how my own coding is.
There’s a hundred different ways to solve this problem. The ASP.NET infrastructure includes something called ViewState, which allows the page and its controls to persist arbitrary data and objects across page views.
There is a single
<form>, but you can have an unlimited number of links and buttons which submit the form in different ways – each one can trigger its own method when the page posts back.A simple way to leverage this in your case is to store the page parameter on the “next page” link. This is a very simple example that assumes you only need to know the page number, but it gets the point across:
…
In this example we set the
CommandArgumentproperty of the LinkButton to the page index we want. The LinkButton triggers theNextPage_Clickmethod to be called, and ASP.NET’s ViewState infrastructure allows the CommandArgument value is persisted.