Solved

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

Posted on 2009-05-06
13
656 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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