How do you add arguments to an ASP button PostBackUrl?
asp.net, button, search
Solution
If you have the PostBackUrl set on your button, then the search box field on your first page, and any other form fields on that page, are already being posted to your search page. The trick is getting access to them in the code-behind for your search.aspx page.
if (Page.PreviousPage != null)
{
TextBox SourceTextBox =
(TextBox)Page.PreviousPage.FindControl("TextBox1");
if (SourceTextBox != null)
{
Label1.Text = SourceTextBox.Text;
}
}
That is one way. There are some shortcuts too, such as using the PreviousPageType directive at the top of your search.aspx page:
<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>
More details on how to use that, as well as the first method, can be found here:
http://msdn.microsoft.com/en-us/library/ms178139.aspx
Problem
I am constructing a search page with a textbox and a button for now, and probably a dropdown to filter results later on. I have my button's PostBackUrl set to my search page (~/search.aspx). Is there an easy way to pass the value in the text box to the search page?