Reputation: 563
Now i send message array as a query string to another page.but when i catch the next page we have a arr.Length know ( normally it shows the intellisense) but in this case it doesn't show.
here is msg_arr pass to the another page
private void check(string keyword , params Array[] msg_arr)
{
switch (keyword.ToUpper())
{
case "SETTELG":
Response.Redirect("../SMSFunction/SeenSMS.ascx?value=1&arr" + msg_arr);
break;
Below code is the next page i wanted to catch that passed value & array(msg_arr).but length doen't work
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Moose = Request.QueryString[1];
}
if (msg_arr != null)
{
if ((msg_arr.Length == 3) && (msg_arr[1].ToLower() == "slett"))
{
}
}
}
here is the second code screenshot,you can see Length not shown
Upvotes: 0
Views: 230
Reputation: 215
You cannot pass whole collection in query string. Only thing you can do is pass an element of collection. i.e. array cannot be passed but array[0].toString() can be. Please do it in a simple way through session variable. Store array in Session variable in Page1.aspx and retrieve on Page2.aspx. Sample code is as follows
Page1.aspx
protected void Page_Load(object sender, EventArgs e)
{
int[] array = { 1, 2, 3, 4, 5 };
Session["Array"] = array; Response.Redirect("About.aspx");
}
Page2.aspx
protected void Page_Load(object sender, EventArgs e)
{
int[] array;
if (Session["Array"] != null)
{
array = (int[])Session["Array"];
if (array.Length == 3)
{
/////implementaion
}
}
}
Upvotes: 1
Reputation: 239724
Quite a few things wrong here.
private void check(string keyword , params Array[] msg_arr)
Is this function really being passed an array of Array
s? I'd have thought string[]
or object[]
to be a more likely type to be passed.
Response.Redirect("../SMSFunction/SeenSMS.ascx?value=1&arr" + msg_arr);
That's going to call ToString()
on msg_arr
, which, it being an array, will produce a result like this:
"../SMSFunction/SeenSMS.ascx?value=1&arrSystem.Array[]"
Array
doesn't override ToString()
, so you get the one from Object
which outputs the fully qualified name of the type - which I assume isn't what you want.
Finally, we reach your second piece of code, but you've not even shown us any code which attempts to set the new msg_arr
variable. But it's not going to be able to get the original value of msg_arr
, since you've not passed that across yet.
You need to decide how you want to pack your array into the query string. If, say, msg_arr
should have been an array of readable strings (params string[] msg_arr
in the check
definition), then you might try something like:
Response.Redirect("../SMSFunction/SeenSMS.ascx?value=1&arr=" + string.Join("|",msg_arr));
where |
is a character that shouldn't appear in the strings being passed. (String.Join
)
You can then reconstruct it back into an array with something like:
protected void Page_Load(object sender, EventArgs e)
{
string[] msg_arr = Request.QueryString["arr"].Split('|');
/* rest of method */
Of course, there may be a concern now if the length of strings (or the number of them) is too large, it may not be appropriate to pass them via a query string at all.
Upvotes: 3