Reputation: 6080
Hi on my master page I have an area to do a search but my search code is on another page(content page) called Search.aspx
when I click the button to do a search query of my database I need to send the string from my master page to my search page and redirect.
Search.aspx code:
protected void Page_Load(object sender, EventArgs e)
{
}
private void PopulateWallPosts(string search)
{
//my search query code
}
Master Page:
protected void Button2_Click(object sender, EventArgs e)
{
string search = TextBox2.Text;
PopulateWallPosts(search);
// this method works fine on local page
// how do I send this to Search.aspx so when button is clicked im redirected to search.aspx and the content of search populates my wallposts?
}
}
Upvotes: 0
Views: 917
Reputation: 1038930
You could set the PostBackUrl property of the button/link:
<asp:Button PostBackUrl="Search.aspx" ID="search" runat="server" Text="Search" />
And in the Search.aspx
page fetch the value from the Request. For example if the textbox is in the master page and is called txtSearch
:
public partial class Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var txtSearch = (TextBox)PreviousPage.Master.FindControl("txtSearch");
if (txtSearch != null)
{
var value = txtSearch.Text;
...
}
}
}
Upvotes: 0
Reputation: 4072
Search.aspx
protected void Page_Load(object sender, EventArgs e)
{
string search = Request.QueryString["search"];
if (!string.IsNullOrEmpty(search))
{
PopulateWallPosts(search);
}
}
private void PopulateWallPosts(string search)
{
//my search query code
}
Master Page:
protected void Button2_Click(object sender, EventArgs e)
{
string search = TextBox2.Text;
Response.Redirect("Search.aspx?search=" + Server.UrlEncode(search));
}
Upvotes: 2
Reputation: 89117
Just have your search box redirect to the search page, passing the arguments on the querystring.
Upvotes: 0