0

I'm not able to read the array passed from the other page with Request.Querystring

//Label1.Text += FID[l]; //Checked the array and it is printing properly.

Response.Redirect("show.aspx?id=" + ID + "&name=" + NAME + "&fileid=" 
                  +FID+"&length="+j);


string fid=string.Empty;
if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["fileid"].ToString())))
{
    fid = Request.QueryString["fileid"].ToString();

}

for (int l = 0; l < length; l++)
{

    Label1.Text += fid[l]; //Printing wrong array
}

Can anybody help me with this.

How can I use Global.aspx file to do this instead of parameter passing.

1
  • what is the value of fid before the for loop? Commented Jun 9, 2011 at 11:26

1 Answer 1

1

Your code makes no sense, first of all If that code is all in the same method then nothing after the Response.Redirect will run.

Second assuming the Response.Redirect is not in the same method as the other code then

if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["fileid"].ToString())))

On the above line you are calling ToString() on something that is already a string and then converting it to a string. If Request.QueryString["fileid"] is null then this will throw a null reference exception. You should do:

if (!string.IsNullOrEmpty(Request.QueryString["fileid"]))

Third fid is a string, Label1.Text is a string. Why are you looping through the string char by char and then adding them onto the end Label1.Text.

Finally fid will contain whatever is passed as the query string param "fileid", it can't contain anything else. If it has the "wrong" value then the "wrong" value is getting passed in the query string.

3
  • Can you tell me how to pass a array in Response.Redirect.
    – Naresh
    Commented Jun 9, 2011 at 13:06
  • 1
    You can't pass an array into a query string as such but providing it is an array of strings you could do string MyString = string.Join(",",MyArray); to turn it into a single string with the each element seperated by a comma. You can then turn it back into an array at the other end with something like string[] MyArray = MyString.Split(','); Commented Jun 9, 2011 at 13:19
  • Why don't u add the above comment to ur answer I will mark it as right answer.
    – Naresh
    Commented Jun 9, 2011 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.