问题
I want to send a string to another page named Reply.aspx using the QueryString.
I wrote this code on first page that must send the text to Reply.aspx:
protected void FReplybtn_Click(object sender, EventArgs e)
{
String s = "Reply.aspx?";
s += "Subject=" + FSubjectlbl.Text.ToString();
Response.Redirect(s);
}
I wrote this code on the Reply.aspx page:
RSubjectlbl.Text += Request.QueryString["Subject"];
But this approach isn't working correctly and doesn't show the text.
What should I do to solve this?
Thanks
回答1:
Though your code should work fine, even if the source string has spaces etc. it should return something when you access query string, please try this also:
protected void FReplybtn_Click(object sender, EventArgs e)
{
String s = Page.ResolveClientUrl("~/ADMIN/Reply.aspx");
s += "?Subject=" + Server.UrlEncode(FSubjectlbl.Text.ToString());
Response.Redirect(s);
}
EDIT:-
void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString.HasKeys())
{
if(!string.IsNullOrEmpty(Request.QueryString["Subject"]))
{
RSubjectlbl.Text += Server.UrlDecode(Request.QueryString["Subject"]);
}
}
}
PS:- Server.UrlEncode is also sugested in comment to this question.
回答2:
this is easy :
First page :
string s = "~/ADMIN/Reply.aspx?";
s += "Subject=" + FSubjectlbl.Text;
Response.Redirect(s);
Second page :
RSubjectlbl.Text = Request.QueryString["Subject"];
来源:https://stackoverflow.com/questions/1483864/send-data-through-the-querystring-with-asp-net