Send data through the QueryString with ASP.NET

陌路散爱 提交于 2019-12-24 12:23:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!