Search Results – Webpage has expired on back button
December 8, 2009
I’ve been asked this a few times now so I thought I would blog my solution to point others to this next time I am asked.
Often times people will create a simple search on their site. The most obvious way to do this is with a simple textbox and button. You then handle the search when the button is clicked in the code-behind.
It may look something like this:
protected void btnSearch_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(txtSearch.Text.Trim()))
{
BindSearch(txtSearch.Text.Trim());
}
}
Pretty straight forward. The problem here is you’re doing a postback to the same page. You won’t have a history of the previous searches in your browser. After doing a search and you want to see what you had for results from the previous search and simply hit back in your browser you’ll see this
So what I have always done to avoid this is to simply do a Response.Redirect to the page instead of just calling the BindSearch() method and put the search term in the query string.
protected void btnSearch_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(txtSearch.Text.Trim()))
{
Response.Redirect("/Search.aspx?search=" + txtSearch.Text.Trim());
}
}
This is a pretty simple solution, does anyone else have a different way to handle this?
-
http://blog.stevienova.com Steve
-
http://www.thedeets.com Ed Kohler
-
Joel
-
Categories
- asp.net (11)
- Blog (1)
- Business (5)
- Conferences (1)
- Errors (3)
- Portfolio (2)
- Reviews (2)
- SQL Server (3)
- Tips (1)
- Uncategorized (1)
- Web Development (13)
-
Archives