views:

69

answers:

6

I am using Querystring to pass values from one page to other. I am tring to implement encoding and decoding using the Server.UrlDecode and urlEncode.

Query string returns a null value, but I can check the values are been sent in URL.

The two pages are:

QueryString.aspx

protected void Page_Load(object sender, EventArgs e)
{


}
protected void Button1_Click(object sender, EventArgs e)
{
    string id = "1";
    string name = "aaaa";

    string url = string.Format("QueryStringValuesTransfer.aspx?{0}&{1}", Server.UrlEncode(id), Server.UrlEncode(name));


    Response.Redirect(url);
}

;;

In another page :

QueryStringValuesTransfer.aspx:

 public partial class QueryStringValuesTransfer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id1 = Server.UrlDecode(Request.QueryString["id"]);
        string name1 = Server.UrlDecode(Request.QueryString["name"]);
        Response.Write(id1 + name1);

    }

}


I am get null values in the id1 and name1.

Any help please..

+1  A: 

That's because your query string should be something like

MyPage.aspx?id=xxx&name=yyy

You are not passing the values, only the names...

Paolo Tedesco
Thanks a lot. its been sorted
Hari Gillala
+3  A: 

Change this line:

string url = string.Format("QueryStringValuesTransfer.aspx?id={0}&name={1}", Server.UrlEncode(id), Server.UrlEncode(name));
onof
+1  A: 
string url = string.Format("QueryStringValuesTransfer.aspx?{0}&{1}", Server.UrlEncode(id), Server.UrlEncode(name));

Should be:

string url = string.Format("QueryStringValuesTransfer.aspx?id={0}&name={1}", Server.UrlEncode(id), Server.UrlEncode(name));
rdkleine
+1  A: 

You aren't specifying a name for the values. You need:

string url = string.Format("QueryStringValuesTransfer.aspx?id={0}&name={1}", Server.UrlEncode(id), Server.UrlEncode(name)); 
Joel Etherton
+1  A: 

When constructing the URL in the first page you should do this:

string url = string.Format("QueryStringValuesTransfer.aspx?id={0}&name={1}", Server.UrlEncode(id), Server.UrlEncode(name));

The query string consists of key-value pairs, you should provide the keys.

Slavo
+2  A: 

Right now you are only setting the values in the querystring, you need to assign them names so you can grab them again:

string url = string.Format("QueryStringValuesTransfer.aspx?id={0}&name={1}", Server.UrlEncode(id), Server.UrlEncode(name));
Chris Pebble
thanks .. sorted
Hari Gillala