Solved

how to pass an array from one Web form to another in ASP.net with c#

Posted on 2009-05-06
13
624 Views
Last Modified: 2012-05-06
how to pass an array from one Web form to another in ASP.net with c#
0
Comment
Question by:tatchis1
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 10

Expert Comment

by:cdebel
ID: 24320721
I would use Session variables...
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 24320732
If you are using Server.Transfer to go to the other page, then store it in the ViewState.

If you are not using Server.Transfer, then store it in the SessionState.

Make sure and remove it from the SessionState once you are done with it.

HTH
- Anthony
0
 
LVL 10

Expert Comment

by:cdebel
ID: 24320763
Here's how i would do it in VB.NET... i'm sure you can translate this quite easily:

        Dim arr(50) As String
        arr(1) = "Hello"
        arr(2) = "World"
        Session("MYARRAY") = arr
        Page.Response.Redirect("http://somewhere.com/myotherpage.aspx")

Then in your other page...
        ArrayFromOtherSite = Session("MYARRAY")

There's of course other methods like passing parameters after the URL like this:
http://somewhere.com/myotherpage.aspx?param1=Hello¶m2=World

but it's up to you...
0
 
LVL 1

Expert Comment

by:CJMilner
ID: 24321024
Serialize the array and then either:
- put it in the viewstate
- post it
- alter the postback url on a button click
- session vars
or querystring (if it's not too long)

Hope this helps

0
 
LVL 9

Accepted Solution

by:
AsishRaj earned 500 total points
ID: 24322267
Well it simple - cdebel has given you the easiest way out
Populate your array
then save your array into the session
    Session("sessionArrayName") = yourArray;

go to which ever page you want

Declare a new array

string[] newarray = new string[arraysize];

newarray = Session("sessionArrayName") ;
0
 

Author Comment

by:tatchis1
ID: 24325184
I want to pass my parmeter using this method but I'm receiving an error.

Response.Redirect("CondemnedStockSummary.aspx?Value1" = txtStart.Text);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:CJMilner
ID: 24325201
Move the equals inside the string and add a + to the end of the string to concatenate the variable with the string. Like this

Response.Redirect("CondemnedStockSummary.aspx?Value1=" + txtStart.Text);
0
 

Author Comment

by:tatchis1
ID: 24325706
Can I do more than one parameters with this method?
Response.Redirect("CondemnedStockSummary.aspx?Value1=" + txtStart.Text);
0
 
LVL 10

Expert Comment

by:cdebel
ID: 24330932
tatchis1: please, next time that you ask a question and get correct answers from people, don't accept a single answer as you did.  

And about your last comment, check my comment #24320763 ... the answer is already there!
0
 
LVL 10

Expert Comment

by:cdebel
ID: 24330951
its especially frustrating when the person who is marked as having the good answer says:
"Well it simple - cdebel has given you the easiest way out is to..."
0
 
LVL 9

Expert Comment

by:AsishRaj
ID: 24349739
I agree, i will post Free Points For You Shortly
0
 
LVL 9

Expert Comment

by:AsishRaj
ID: 24349756
0
 
LVL 10

Expert Comment

by:cdebel
ID: 24351193
All what the askers have to do is to press the "REQUEST ATTENTION" button if my memory is good, then ask to split the points and the manager of this zone will help.

The important thing is that the asker understand how to do splits points for next time because if he keep doing this, people might refuse to answer him.  (same if he give a grade E to someone who gave a good answer too).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now