C# 将字符串发送到另一页
您好,在我的母版页上,我有一个搜索区域,但我的搜索代码位于另一个名为search.aspx的页面(内容页)C# 将字符串发送到另一页,c#,asp.net,html,C#,Asp.net,Html,您好,在我的母版页上,我有一个搜索区域,但我的搜索代码位于另一个名为search.aspx的页面(内容页) protected void Page_Load(object sender, EventArgs e) { string search = Request.QueryString["search"]; if (!string.IsNullOrEmpty(search)) { PopulateWallPosts(search); } } pr
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
}
当我单击按钮对数据库进行搜索查询时,我需要将字符串从母版页发送到搜索页并重定向
Search.aspx代码:
protected void Page_Load(object sender, EventArgs e)
{
}
private void PopulateWallPosts(string search)
{
//my search query code
}
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?
}
}
母版页:
protected void Page_Load(object sender, EventArgs e)
{
}
private void PopulateWallPosts(string search)
{
//my search query code
}
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?
}
}
您可以设置按钮/链接的属性:
<asp:Button PostBackUrl="Search.aspx" ID="search" runat="server" Text="Search" />
只需将搜索框重定向到搜索页面,在查询字符串上传递参数即可 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
}
母版页:
protected void Button2_Click(object sender, EventArgs e)
{
string search = TextBox2.Text;
Response.Redirect("Search.aspx?search=" + Server.UrlEncode(search));
}
@Garrith Graham,文本框在哪里?在母版页中?如果Search.aspx是否来自同一个master?@Garrith Graham,那么您应该能够
var txtSearch=(TextBox)PreviousPage.master.FindControl(“TextBox1”)
获取Search.aspx
中相应的文本框,并使用.Text
属性获取文本。