Solved

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

Posted on 2009-05-06
13
616 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&param2=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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

17 Experts available now in Live!

Get 1:1 Help Now