开发者

sending a string to another page

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 s开发者_如何转开发earch 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?

    }
}


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));
}


Just have your search box redirect to the search page, passing the arguments on the querystring.


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;
            ...
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜