?
Solved

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

Posted on 2009-05-06
13
Medium Priority
?
728 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:Christian de Bellefeuille
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:Christian de Bellefeuille
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1500 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
 
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:Christian de Bellefeuille
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:Christian de Bellefeuille
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:Christian de Bellefeuille
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 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